charafau / json2builtvalue

Json to Dart built_value classes generator
Apache License 2.0
153 stars 24 forks source link

Web: Does not generate all sub classes that Json Contains #7

Open jibraniqbal666 opened 5 years ago

jibraniqbal666 commented 5 years ago
{
    "message_type": "GET_STORY",
    "status": "Success",
    "response_code": "1200",
    "details": {
        "content": [
            {
                "id": "1cbee0cc-11f2-11e9-8fc7-5130b7f9b02f",
                "story": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla id justo vitae odio elementum elementum vel sit amet arcu. Maecenas posuere scelerisque risus, at cursus massa sodales quis. Vestibulum sit amet nisl vestibulum, laoreet arcu et, egestas justo. Fusce egestas viverra enim quis hendrerit. Nulla suscipit turpis et luctus tincidunt. Quisque ac bibendum odio, at iaculis est. Fusce eget ipsum sed augue varius rhoncus nec ac lorem. Nullam eu est bibendum, aliquet sapien id, congue sem. Duis pharetra eros consequat felis tempor cursus. Donec a accumsan lectus, sit amet condimentum est. Duis ac nisl nisl. Etiam dignissim lacinia ante, quis luctus sem accumsan non. Praesent risus turpis, viverra et mattis molestie, lobortis vulputate mi. Aliquam erat volutpat.\nCras luctus erat ligula, sed dignissim sapien consectetur non. Aenean ut dictum odio. Sed accumsan rutrum nisl id pulvinar. Vestibulum dolor ex, dignissim vel lacus ut, cursus bibendum lectus. Sed pretium lobortis lacinia. Aliquam tempor nunc et egestas imperdiet. Aliquam in nisl sed neque venenatis eleifend vel quis magna. Nullam in maximus est, sit amet consequat magna. In sed rhoncus eros, nec ornare diam. Mauris vel mi non nisi ultricies consectetur.\r\nSuspendisse nibh elit, fringilla id massa in, eleifend tristique mauris. Nunc euismod nibh sit amet quam tincidunt, a ultrices mauris laoreet. Donec ut cursus augue. Quisque eu molestie erat. Nullam eget consequat sapien. Donec vitae justo et lacus posuere aliquet. Sed condimentum blandit nisi nec ullamcorper. Nulla lacinia varius nisl, sed mollis nulla tempor at. Quisque ex sem, consectetur id nulla ut, tristique tincidunt turpis. Suspendisse quis lacinia elit.\r\nMauris eget eleifend lorem. Donec laoreet sem lorem, in fringilla sem maximus a. Sed libero nisl, consectetur fringilla eros vitae, interdum auctor augue. Mauris aliquam turpis lorem, id fermentum dui porta nec. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus erat massa, imperdiet sed auctor a, tristique nec felis. Fusce eu eros vitae ipsum vulputate viverra et at nulla. Phasellus consectetur est lectus, in placerat sapien vestibulum at. Fusce ex arcu, condimentum ut nisi eget, venenatis maximus justo. Nulla ac ullamcorper massa, quis pharetra libero. Suspendisse dolor magna, congue id est in, egestas tristique nisl. Aliquam sed augue vitae neque hendrerit mollis et sed neque. Suspendisse aliquam lorem vel iaculis facilisis.\r\nFusce gravida lorem commodo elit tincidunt condimentum in et urna. Vivamus suscipit ac nibh non ornare. Donec ultricies nibh sit amet laoreet vestibulum. Phasellus id rutrum nibh, id maximus erat. Ut tincidunt dignissim viverra. Duis vitae velit nulla. Nam id nibh in augue rutrum consequat ac et enim. Pellentesque ut odio tempus, pharetra elit suscipit, posuere elit. Vivamus eu lacus lobortis, consectetur orci vitae, rhoncus nisi. Nullam massa orci, feugiat sit amet imperdiet vitae, pretium id orci. Pellentesque malesuada laoreet mauris, et rhoncus sem facilisis at. Sed a pretium leo, vel ornare massa. Praesent id eros eu metus egestas dignissim. Morbi varius augue a pellentesque rhoncus. Ut et ligula vestibulum, iaculis ante id, dictum lorem. ",
                "category": "lorem_ipsum",
                "thumbnailPath": "some_path_to_thumbnail",
                "heading": "LOREM IPSUM LOREM IPSUM LOREM IPSUM",
                "annonymous": true,
                "createdAt": "2019-01-06T20:31:57.000+0000",
                "no_of_likes": 0,
                "no_of_comments": 0
            }
        ],
        "pageable": {
            "sort": {
                "sorted": true,
                "unsorted": false
            },
            "pageSize": 20,
            "pageNumber": 0,
            "offset": 0,
            "unpaged": false,
            "paged": true
        },
        "last": true,
        "totalPages": 1,
        "totalElements": 5,
        "first": true,
        "sort": {
            "sorted": true,
            "unsorted": false
        },
        "numberOfElements": 5,
        "size": 20,
        "number": 0
    }
}

output:


import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';

part 'stories.g.dart';

abstract class Stories implements Built<Stories, StoriesBuilder> {
  Stories._();

  factory Stories([updates(StoriesBuilder b)]) = _$Stories;

  @BuiltValueField(wireName: 'message_type')
  String get messageType;
  @BuiltValueField(wireName: 'status')
  String get status;
  @BuiltValueField(wireName: 'response_code')
  String get responseCode;
  @BuiltValueField(wireName: 'details')
  Details get details;
  String toJson() {
    return json.encode(serializers.serializeWith(Stories.serializer, this));
  }

  static Stories fromJson(String jsonString) {
    return serializers.deserializeWith(
        Stories.serializer, json.decode(jsonString));
  }

  static Serializer<Stories> get serializer => _$storiesSerializer;
}
library details;

import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';

part 'details.g.dart';

abstract class Details implements Built<Details, DetailsBuilder> {
  Details._();

  factory Details([updates(DetailsBuilder b)]) = _$Details;

  @BuiltValueField(wireName: 'content')
  BuiltList<Content> get content;
  @BuiltValueField(wireName: 'pageable')
  Pageable get pageable;
  @BuiltValueField(wireName: 'last')
  bool get last;
  @BuiltValueField(wireName: 'totalPages')
  int get totalPages;
  @BuiltValueField(wireName: 'totalElements')
  int get totalElements;
  @BuiltValueField(wireName: 'first')
  bool get first;
  @BuiltValueField(wireName: 'sort')
  Sort get sort;
  @BuiltValueField(wireName: 'numberOfElements')
  int get numberOfElements;
  @BuiltValueField(wireName: 'size')
  int get size;
  @BuiltValueField(wireName: 'number')
  int get number;
  String toJson() {
    return json.encode(serializers.serializeWith(Details.serializer, this));
  }

  static Details fromJson(String jsonString) {
    return serializers.deserializeWith(
        Details.serializer, json.decode(jsonString));
  }

  static Serializer<Details> get serializer => _$detailsSerializer;
}

the whole content, sort and paggeable class missing

webskydavid commented 5 years ago

Have the same issue, the generation goes only 2 level depth. If the second one has also an object it will not generate. I try to solve it by moving the second level to level 0 and generate again the whole code. By hand I added the missing classes, but it tells me that

[SEVERE] built_value_generator:built_value on lib/core/models/event/extended_properties.dart (cached):
Error in BuiltValueGenerator for abstract class ExtendedProperties implements Built<ExtendedProperties, dynamic>.
Please make the following changes to use BuiltValue:

1. Make field private have non-dynamic type. If you are already specifying a type, please make sure the type is correctly imported.
2. Make field shared have non-dynamic type. If you are already specifying a type, please make sure the type is correctly imported.

Here is the extended_properties class

library extended_properties;

import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';

part 'extended_properties.g.dart';

abstract class ExtendedProperties
    implements Built<ExtendedProperties, ExtendedPropertiesBuilder> {
  ExtendedProperties._();

  factory ExtendedProperties([updates(ExtendedPropertiesBuilder b)]) =
      _$ExtendedProperties;

  @BuiltValueField(wireName: 'private')
  Private get private;
  @BuiltValueField(wireName: 'shared')
  Shared get shared;
  String toJson() {
    return json
        .encode(serializers.serializeWith(ExtendedProperties.serializer, this));
  }

  static ExtendedProperties fromJson(String jsonString) {
    return serializers.deserializeWith(
        ExtendedProperties.serializer, json.decode(jsonString));
  }

  static Serializer<ExtendedProperties> get serializer =>
      _$extendedPropertiesSerializer;
}

Private class

library private;

import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';

part 'private.g.dart';

abstract class Private implements Built<Private, PrivateBuilder> {
  Private._();

  factory Private([updates(PrivateBuilder b)]) = _$Private;

  @BuiltValueField(wireName: 'eventAttendeeList')
  String get eventAttendeeList;
  String toJson() {
    return json.encode(serializers.serializeWith(Private.serializer, this));
  }

  static Private fromJson(String jsonString) {
    return serializers.deserializeWith(
        Private.serializer, json.decode(jsonString));
  }

  static Serializer<Private> get serializer => _$privateSerializer;
}

Shared class

library shared;

import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';

part 'shared.g.dart';

abstract class Shared implements Built<Shared, SharedBuilder> {
  Shared._();

  factory Shared([updates(SharedBuilder b)]) = _$Shared;

  @BuiltValueField(wireName: 'eventAttendeeList')
  String get eventAttendeeList;
  String toJson() {
    return json.encode(serializers.serializeWith(Shared.serializer, this));
  }

  static Shared fromJson(String jsonString) {
    return serializers.deserializeWith(
        Shared.serializer, json.decode(jsonString));
  }

  static Serializer<Shared> get serializer => _$sharedSerializer;
}
{
    "kind": "calendar#event",
    "etag": "3108271087171000",
    "id": "clj64dr2c5h66b9nclij8b9kcksmab9p70pj0bb26so34e36c4pjcp1m6g",
    "status": "confirmed",
    "htmlLink": "https://www.google.com/calendar/event?eid=Y2xqNjRkcjJjNWg2NmI5bmNsaWo4YjlrY2tzbWFiOXA3MHBqMGJiMjZzbzM0ZTM2YzRwamNwMW02ZyBmcGlxMmF1bGR0bm8zM2k1M2phYWMwazIzOEBn",
    "created": "2019-04-01T16:19:03.000Z",
    "updated": "2019-04-01T16:19:03.660Z",
    "summary": "Performance Ar",
    "location": "Vattenfall IT Services Poland Sp z o.o., Tadeusza Gruszczyńskiego 2, 44-100 Gliwice, Polska",
    "creator": {
        "email": "webskydavid@gmail.com",
        "displayName": "david ftaton"
    },
    "organizer": {
        "email": "fpiq2auldtno33i53jaac0k238@group.calendar.google.com",
        "displayName": "Me & She",
        "self": true
    },
    "start": {
        "dateTime": "2019-04-04T14:30:00+02:00",
        "timeZone": "Europe/Berlin"
    },
    "end": {
        "dateTime": "2019-04-04T15:00:00+02:00",
        "timeZone": "Europe/Berlin"
    },
    "iCalUID": "clj64dr2c5h66b9nclij8b9kcksmab9p70pj0bb26so34e36c4pjcp1m6g@google.com",
    "sequence": 0,
    "extendedProperties": {
        "private": {
            "eventAttendeeList": "string"
        },
        "shared": {
            "eventAttendeeList": "string"
        }
    },
    "reminders": {
        "useDefault": false,
        "overrides": [
            {
                "method": "popup",
                "minutes": 10
            }
        ]
    }
}