Skip to content
This repository was archived by the owner on Apr 11, 2023. It is now read-only.
This repository was archived by the owner on Apr 11, 2023. It is now read-only.

Consider support for serialization/deserialization of top level arrays #14

Open
@TommyVisic

Description

@TommyVisic

I didn't see a built-in way to handle top-level arrays, e.g.:

[
  {
    "name": "Jorge",
    "faveNumber": 4
  },
  {
    ...
  }
]

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?).

List<Video> videos = new LinkedList<Video>();
if (parser.nextToken() == JsonToken.START_ARRAY) {
   while (parser.nextToken() != JsonToken.END_ARRAY) {
      Video video = Video__JsonHelper.parseFromJson(parser);
      videos.add(video);
   }
}

Maybe JsonHelper types could know how to serialize/deserialize arrays of their model types. Something like:

public static final List<MyModel> parseFromJsonArray(JsonParser jp)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions