jpganz18 :
I have tried to look for an answer on this but realized there are multiple similar but none matches this one.
I have a JSON object with this structure
{
"model": {
"serie" : "123456",
"id" : "abc123"
/// many fields
},
"externalModel": {
"serie" : "123456",
"fieldX" : "abcde"
// many fields as well
}
and I'm doing this at my code:
ObjectMapper mapper = new ObjectMapper();
MyObject object = mapper.readValue(hit.getSourceAsString(), MyObject.class);
where MyObject has this form:
@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyObject {
@JsonProperty("serie")
String serie;
@JsonProperty("id")
Long id;
MyObject() {}
}
When I convert I don't get any exception, but rather I get myObject with all values set to null
I have no idea what could be wrong since no exception returned, any idea?
user7294900 :
You need to use root property model
,
You can rename MyObject
to MyModel
and create a MyObject
@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyObject{
@JsonProperty("model")
MyModel model;
}
and then check model
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=329740&siteId=1