I get JSON response from API:
{
"value": [{
"some-field": "blah-blah",
...
}]
}
There is always one object in the array so I don't want to store a pojo like this:
public class Foo {
private List<InnerClass> value;
}
but like this:
public class Foo {
private String field1;
private String field2;
...
}
How do I create custom deserializer for it?
I have tried the following:
public class CustomDeserializer extends StdDeserializer<Foo> {
public CustomDeserializer(Class<Foo> clazz) {
super(clazz);
}
public CustomDeserializer() {
this(null);
}
@Override
public Foo deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
String s = jsonNode.get("value").get(0).toString();
Foo obj = new ObjectMapper().readValue(s, Foo.class);
return obj;
}
}
but there is some kind of circle issues and it doesn't work.