google / built_json.dart Goto Github PK
View Code? Open in Web Editor NEWDeleted, use built_value instead.
Home Page: https://github.com/google/built_value.dart
License: BSD 3-Clause "New" or "Revised" License
Deleted, use built_value instead.
Home Page: https://github.com/google/built_value.dart
License: BSD 3-Clause "New" or "Revised" License
Having more canonical, "pretty" JSON is nice โ especially when saving to disk or interoperating with non-Dart systems.
Is that explicitly a non-Goal?
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';
}
quiver: '>=0.21.0 <0.22.0'
This breaks deserialization of maps.
The serializers currently don't check genericType. Investigate to see whether it makes sense.
At v0.0.2 nulls are written explicitly in the JSON.
Could be used for making wire format smaller later, introduce it so we don't need an interface change to add it.
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)
The nested builder needs to be created before calling 'replace' on it.
Since they are referenced in the tool directory.
Currently, serializer throws when it hits a null.
An unused variable called 'value' is generated.
Currently only fields of types in the current file are checked, need to actually do a proper search for all serializable types.
Wouldn't it be 8080 by default?
This would be nicer than a for loop plus boolean.
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 :-) )
Serializers use 'Object' as a map in a way that generates analyzer warnings.
Can use an iterator instead of one for loop and a bool to switch between keys and values.
Maybe just Serializer(s)? They can be used with a prefix if needed.
e.g. two classes in a file, serializer declaration points to wrong one.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.