Andreas Köberle
Andreas Köberle

Reputation: 110892

How to handle json with different type but same key in jackson

I request a rest service where the json result holds a list of place objects o just one place object but both with the same key:

{
    place:[{lat:12, lon:12}, {lat:12, lon:12}]
}

or

{
    place: {lat: 12, lon:12}
}

Is there a way to handle this with the jackson json parser to I've got always a list of objects?

Upvotes: 0

Views: 692

Answers (1)

StaxMan
StaxMan

Reputation: 116502

Sure. Have you tried it? For first example, it would seem like your object model would be something like:

public class Places {
  public List<Place> place:

}

public class Place { public int lat, lon; }

and you would get expected JSON.

Upvotes: 1

Related Questions