Git Product home page Git Product logo

built_json.dart's Issues

Request: option for "pretty" JSON?

Having more canonical, "pretty" JSON is nice โ€“ especially when saving to disk or interoperating with non-Dart systems.

Is that explicitly a non-Goal?

allow non-concrete serialized types provided all implementations are serializable

See google/built_value.dart#22

I was forced to create a custom serialiser (https://github.com/Andersmholmgren/vcore/blob/master/lib/src/model/model.dart#L118) because I have properties using a base type.

abstract class Classifier implements NamedElement {}

abstract class GenericType
    implements Built<GenericType, GenericTypeBuilder>, Classifier {
  Classifier get base;
  BuiltMap<TypeParameter, Classifier> get genericTypeValues;
...
}

Properties like base and genericTypeValues need to use the abstract type Classifier. The Json serialiser generator doesn't cope with this so I needed to create a custom serialiser

Serializers serializers =
    (_$serializers.toBuilder()..add(_classifierSerializer)).build();

//final x = new SerializersBuilder()..;
final _ClassifierSerializer _classifierSerializer = new _ClassifierSerializer();

class _ClassifierSerializer implements StructuredSerializer<Classifier> {
  @override
  Classifier deserialize(Serializers serializers, Iterable serialized,
      {FullType specifiedType: FullType.unspecified}) {
    return serializers.deserialize(serialized);
  }

  @override
  Iterable serialize(Serializers serializers, Classifier object,
      {FullType specifiedType: FullType.unspecified}) {
    return object != null ? serializers.serialize(object) : [];
  }

  @override
  Iterable<Type> get types => [Classifier];

  @override
  String get wireName => 'Classifier';
}

Add serializer context

Could be used for making wire format smaller later, introduce it so we don't need an interface change to add it.

Doesn't cope with null value in nullable field

I have a field declared in a Built class as

  @nullable
  Object get defaultValue;

and similarly in the corresponding builder

The generated serialization code for this field looks like

      'defaultValue',
      serializers.serialize(object.defaultValue,
          specifiedType: FullType.unspecified),

When this runs with a value for object.defaultValue of null it blows up with the following

    Bad state: No serializer for 'Null'.
    #0      BuiltJsonSerializers.serialize (package:built_json/src/built_json_serializers.dart:34:9)
    #1      _$PropertySerializer.serialize (package:vcore/src/model/model.g.dart:168:19)
    #2      BuiltJsonSerializers.serialize (package:built_json/src/built_json_serializers.dart:55:14)
    #3      BuiltSetSerializer.serialize.<anonymous closure> (package:built_json/src/built_set_serializer.dart:28:31)
    #4      MappedIterator.moveNext (dart:_internal/iterable.dart:393)
    #5      List.List.from (dart:core-patch/array_patch.dart:40)
    #6      Iterable.toList (dart:core/iterable.dart:341)
    #7      BuiltJsonSerializers.serialize (package:built_json/src/built_json_serializers.dart:56:14)
    #8      _$ValueClassSerializer.serialize (package:vcore/src/model/model.g.dart:243:19)
    #9      BuiltJsonSerializers.serialize (package:built_json/src/built_json_serializers.dart:38:42)
    #10     VCoreModelGenerator.generate.<generate_async_body> (package:vcore_generator/src/vcore_model_generator.dart:31:37)

Possible to use transformers?

Is it possible to use a transformer rather than mix the value class and the generated class in the same directory? The current example looks a little cumbersome.

(I dont fully understand how it works - so if this not possible please ignore :-) )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.