-
Notifications
You must be signed in to change notification settings - Fork 423
Closed
Description
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.
SvenSchoene, vanlooverenkoen, fousa, aspiringant, loveforgeter and 68 moretolotrasamuel, vanlooverenkoen, arpitignite, k-paxian, taoyimin and 20 moretolotrasamuel, arpitignite, vanlooverenkoen, deadsoul44, jarekb123 and 11 moretolotrasamuel, vanlooverenkoen, deadsoul44, jarekb123, ResoDev and 9 more
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
kevmoo commentedon May 24, 2019
Interesting idea. It is currently not supported.
vanlooverenkoen commentedon Jun 20, 2019
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
jayden320 commentedon Aug 12, 2019
I really need this feature. Is it supported now?
vanlooverenkoen commentedon Oct 23, 2019
Is there a roadmap for this feature? What timeframe could we expect for a P2?
k-paxian commentedon Dec 21, 2019
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
vanlooverenkoen commentedon Dec 23, 2019
Thanks. but I need to use json_serializable. Because I am using retrofit.dart that uses toJson and fromJson.
kevmoo commentedon Dec 23, 2019
PRs welcome here!
NicolaVerbeeck commentedon Dec 24, 2019
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
mokai commentedon Jan 3, 2020
Necessary function !
taoyimin commentedon Jan 3, 2020
I really need this feature!
masewo commentedon Mar 28, 2020
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.
kevmoo commentedon Mar 28, 2020
@masewo and @NicolaChimerapps – I'll happily take a solid PR with testing, etc
16 remaining items
kevmoo commentedon Dec 28, 2021
There is NOT an open PR on this. That was a mistake.
The issue here: we need some other syntax for key that's not a
String
because anyString
can be a valid key in a JSON map. So we'd need to supportList<String>
for key – or add another value. Both of which are quite a bit of work!ad-on-is commentedon Jan 29, 2022
How about something like
example: Add an example demonstrating how to do nested fields
kevmoo commentedon Feb 3, 2022
After consideration, I've decided not to invest time here. It adds a LOT of complexity.
If you still want this feature, it's pretty easy to implement with a
JsonConverter
See https://github.com/google/json_serializable.dart/blob/master/example/lib/nested_values_example.dart
qevka commentedon Feb 7, 2022
That would be nice if JsonConvert was actually working. I am having the same problem that is mentioned here: #1066
I tried downgrading my build_runner and json_annotation packages and also tried just using your code directly neither worked.
Alameen688 commentedon Mar 21, 2022
In my case I didn't need the
toJson
data to transform data back to the original structure I just needed to read the correct data andreadValue
worked perfectly fine in combination with deep_pick.Veeksi commentedon Apr 14, 2022
I am also having this exact same problem with the explicit json converter
JPaulMora commentedon Dec 16, 2022
Chiming in to show support/need for this functionality.
rignaneseleo commentedon Nov 15, 2023
Up
EvGeniyLell commentedon Dec 21, 2023
I'm use next solution
where
nestedReader
isfor this test
result will be
update:
also we can declare
and use it as
devnta commentedon Mar 11, 2024
There is no solution to this problem in 2024
creativecreatorormaybenot commentedon Mar 11, 2024
@phamquoctrongnta check 2dfffd0.
Add JsonSerializabel.constructor
example: Add an example demonstrating how to do nested fields