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

Doesn't cope with null value in nullable field #23

Closed
Andersmholmgren opened this issue Apr 30, 2016 · 3 comments
Closed

Doesn't cope with null value in nullable field #23

Andersmholmgren opened this issue Apr 30, 2016 · 3 comments

Comments

@Andersmholmgren
Copy link

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)
@Andersmholmgren
Copy link
Author

I don't see any special treatment of fields annotated as @nullable in the json serialization generator code

@davidmorgan
Copy link
Contributor

Thanks. This is a regression, it used to work by accident but there was never explicit handling/tests. Will take a look ASAP. Related #6

@davidmorgan
Copy link
Contributor

Pull request: #24

You're welcome to review, or I'll ask someone here to take a look if you prefer.

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