k-paxian / dart-json-mapper

Serialize / Deserialize Dart Objects to / from JSON
https://pub.dev/packages/dart_json_mapper
Other
400 stars 33 forks source link

Flutter Json Mapper (json_mapper) is failing to deserialize Enum #197

Closed Dinesh2411 closed 1 year ago

Dinesh2411 commented 2 years ago

Hi guys I have the dart_json_mapper: ^2.2.4+2 installed in my flutter project.

Everything is working fine, but while deserializing an enum from one of my classes it's showing an error.

Visitor Model Class

@jsonSerializable class Visitor { @JsonProperty(name: 'Gender') GenderEnum gender = GenderEnum.NA; }

Gender Enum `import 'package:dart_json_mapper/dart_json_mapper.dart';

@jsonSerializable enum GenderEnum { Male, Female, NA }`

The error

I/flutter ( 2177): ErrorInstance of 'DeserializationContext' I/flutter ( 2177): FormatException: Unexpected character (at character 1) I/flutter ( 2177): NA I/flutter ( 2177): ^

Note:

I have followed the documentation https://pub.dev/packages/dart_json_mapper/example But still, no success don't know what step I am missing

k-paxian commented 2 years ago

Can you share the actual code which is failing? Including JSON text? Ideally the simple reproduction excerpt