Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize without key #1060

Open
sulthanalihsan opened this issue Dec 6, 2021 · 2 comments
Open

Serialize without key #1060

sulthanalihsan opened this issue Dec 6, 2021 · 2 comments

Comments

@sulthanalihsan
Copy link

sulthanalihsan commented Dec 6, 2021

Hi, i just wanna ask something like, sometime our backend dev return the response like this

[ { "data" : "data1"}, { "data" : "data2"}, { "data" : "data3"} ]

how to handle that with JsonSerializable, a list data without key, thankyou

@morlay
Copy link

morlay commented Dec 9, 2021

It could be work well with custom wrapper

class ListWrap {
    List<dynamic> list
    
    factory ListWrap.fromJson(List<dynamic> json) => _$ListWrapToJson({"list": json});

    List<dynamic> toJson() => _$ListWrapToJson(this)["list"]
}

But will not work with freezed rrousselGit/freezed#451

may consider add a pair option fromJson, toJson to @JsonSerializable
or even just @JsonKey(inline:true)

@eshfield
Copy link

Are there any updates to this problem?

Can't find any mention in the internet about serializing JSON with root list structure.

or even just @JsonKey(inline:true)

This looks great for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants