k-paxian / dart-json-mapper

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

The `@JsonProperty.name` support for aliases doesn't work as advertised #181

Closed yangxiaoweihn closed 2 years ago

yangxiaoweihn commented 2 years ago
sdk: ">=2.15.1 <3.0.0"
path: ^1.8.1
dart-json-mapper: 2.2.1+3

tested result: Jsonproperty annotation only support the primary name and the last aliases, other aliases ignored.

code:

/// entity
@jsonSerializable
class Category {
    @JsonProperty(name: ['id', 'id_a', 'id_b', 'id_test'],)
    int id = 0;
    String uuid = '';
}
/// test
List<String> test = [
                '''{"id": 90, "name": "id"}''',
                '''{"id_a": 91, "name": "id_a"}''',
                '''{"id_test": 92, "name": "id_test"}''',
                '''{"id_b": 93, "name": "id_b"}''',
            ];
for (var element in test) {
    Log.log(">>>>>  ${JsonMapper.deserialize<Category>(element).toString()}");
    Log.log("\n");
}

/// compiled reflectable

aaaaa

/// out put image

so, Jsonproperty annotation only support the first id and the last id_test, id_a and id_b in the middle are ignored

k-paxian commented 2 years ago

Thank you so much, delivered in 2.2.2 🎉