json_serializable.dart
json_serializable.dart copied to clipboard
Can multiple fields have same @JsonKey name?
I'm using JsonSerializable for json request parsing from Django server where I user content_type feature.
That means that I have generic foreign relationship between Django models which consist of object_id, (Primary key of entity in foreign relationship) content_type (table name of entity in foreign relationship) and content_object (object itself that is referenced).
I would like to have in Flutter response class (@JsonSerializable()) to have multiple fields (final ResponseType1 responseType1; final ResponseType2 responseType2; ...) which have same @JsonKey(name: 'content_object') for each one. There will always be single field of (ResponseType1, ResponseType2, ...) present and rest will be null. I want to only correct one to be parsed and rest of fields to be left with null value. Is that possible?