Maybe it's simple, but I'm stuck... I have an app using Spring Boot and springframework.web.client.RestTemplate, so there's Jackson on backseat doing JSON job automatically.
I want to deserialize REST input with JSON like this:
{
"serial_no": 12345678,
"last_dt": [
{
"lp": "2022-04-22T15:00:00"
},
{
"bp": null
},
{
"dp": "2022-04-22T00:00:00"
},
{
"iv": "2022-04-22T00:05:11"
}
]
}
Please, help me to create POJO for this model... If I created following classes (simplified with lombok):
@Data
public class LastDt {
@JsonProperty("lp")
private String lp;
@JsonProperty("bp")
private String bp;
@JsonProperty("dp")
private String dp;
@JsonProperty("iv")
private String iv;
}
@Data
public class Device {
@JsonProperty("serial_no")
private Long serialNo;
@JsonProperty("last_dt")
private List<LastDt> lastDt;
}
deserialization is technically ok - I got an object with serialNo Long value and unfortunatelly list of 4 instances of class LastDt: first instance (lastDt[0]) had field "lp" with value and "bp", "dp", "iv" null; second (lastDt[1]): "bp" with value and "lp", "dp", "iv" null and so on - only one value was set and others are not. That's far from what I want to get. As you can see, there's four pair-like anonymous objects with different key names, so my model is bad, and I know this, but got stuck trying to create other ones... Can anyone help me?
last_dtto be an object instead of an array?Devicelike in your json :last_dtinstead of lastDt ?