-
Notifications
You must be signed in to change notification settings - Fork 125
Consider support for serialization/deserialization of top level arrays #14
Comments
I stumbled into the same problem. The only way I found to generalize this easily is to use a "closure" although that's not satisfactory. |
In case someone needs it, I've created a small gist to help parse a JSON stream knowing its corresponding Java class: https://gist.github.com/ratamovic/c6497504cd8edf87ef38 |
this is a good start though be aware that this is not proguard safe. |
Where I can find example how to use ParserHelper class? |
Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed. |
Looks like this issue has been abandoned. Any update here? It'd be hugely valuable to have. Can also try to dig in and PR a fix with a little guidance. |
A pretty bad¹ but easy solution to whip up: A slightly less bad solution, but somewhat more complicated solution: The best solution is native support in the library, but I have a different day job now. :/ ¹ it's bad because it involves allocating a chunk of memory roughly equal to the length of your string. |
I didn't see a built-in way to handle top-level arrays, e.g.:
Our current solution is to iterate through the array, making calls to the appropriate JsonHelper type for each object. Not a big deal really, but we'd need to duplicate this for each kind of model that's in a top-level array, since I don't see a way to generalize this into a helper method (anyone else?).
Maybe JsonHelper types could know how to serialize/deserialize arrays of their model types. Something like:
The text was updated successfully, but these errors were encountered: