google / json_serializable.dart

Generates utilities to aid in serializing to/from JSON.
https://pub.dev/packages/json_serializable
BSD 3-Clause "New" or "Revised" License
1.54k stars 392 forks source link

Generate an object to access json keys #1400

Closed ChreSyr closed 4 months ago

ChreSyr commented 4 months ago

Hey !

It would be very nice to have a way to link the properties to their json keys. It would reduce the margin of error. For exemple, in my case, it would be for Firebase filters.

from : Filter('datetime_start', isGreaterThan: ...) to : Filter(MyModel.jsonKeys.dateTimeStart, isGreaterThan: ...)

I know there already is the parameter 'create_field_map' which allows for Filter(MyModel.fieldMap['dateTimeStart'], isGreaterThan: ...) but it's safer to use properties instead of strings.

ArthurREGNARD commented 4 months ago

greate feature, need it !!

aliaksei-liavonik commented 4 months ago

That sounds good, also need it. To specify the list of fields for JSON_API-based server to return only needed fields, instead of listing all of the fields by hand from DTO objects