It would be great if we could directly access nested items in the name String of @JsonKey. Consider this Json:
"root_item": {
"items": [
{
"name": "first nested item"
},
{
"name": "second nested item"
}
]
}
I would like to do:
@JsonKey(name: "root_item/items")
List<NestedItem> nestedItems;
Sorry if this is already possible, but i could not find anything.
Interesting idea. It is currently not supported.
This should really be added. Now we have to create extra objects because we had to use a crappy backend. Using a simple api to flatten your backend models
I really need this feature. Is it supported now?
Is there a roadmap for this feature? What timeframe could we expect for a P2?
If you guys are still waiting for that feature, this library already has it implemented
https://github.com/k-paxian/dart-json-mapper#nesting-configuration
@KorbinianMossandl thank you for a great idea! This thing is called rfc6901
Thanks. but I need to use json_serializable. Because I am using retrofit.dart that uses toJson and fromJson.
PRs welcome here!
I am working on an implementation for this.
Rough draft can be found here: https://github.com/Chimerapps/json_serializable/tree/feature/json_path
WIP, not ready for production
Necessary function !
I really need this feature!
I forked @NicolaChimerapps fork and corrected two small errors:
https://github.com/masewo/json_serializable/tree/feature/json_path
For now it is working for me.
@masewo and @NicolaChimerapps 鈥撀營'll happily take a solid PR with testing, etc
It's wishful for me.
Any update on this ?
Bumping as this is a must have.
Pull requests welcome 鈥撀燽eyond the core features offered now, this package is a "beyond work hours" project.
If #783 gets merged, this will be possible, albeit in a convoluted manner:
@JsonSerializable()
class MyObject {
@JsonKey(name: 'myRegularField')
final String myRegularField;
@JsonKey(extra: true)
final String myNestedField;
MyObject({
required this.myRegularField,
required this.myNestedField,
});
factory MyObject.fromJson(Map<String, dynamic> json) {
return _$MyObjectFromJson(
json,
myNestedField: json['myInnerObject']['myNestedField'] as String,
);
}
Map<String, dynamic> toJson() {
final output = _$MyObjectToJson(this);
output['myInnerObject'] = {'myNestedField': myNestedField};
return output;
}
}
Most helpful comment
Pull requests welcome 鈥撀燽eyond the core features offered now, this package is a "beyond work hours" project.