Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

allow non-concrete serialized types provided all implementations are serializable #22

Closed
Andersmholmgren opened this issue Apr 25, 2016 · 2 comments

Comments

@Andersmholmgren
Copy link

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';
}
@davidmorgan
Copy link
Contributor

Sorry, I thought I'd replied to this. Yes, this should be supported. I'll take a look.

@davidmorgan
Copy link
Contributor

This should do it

#26

As before, happy if you want to review, or I'll find someone here. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants