I'm trying to call a rest endpoint which returns a pojo object which looks like this:
public class Process {
@JsonProperty("id")
private String id = null;
@JsonProperty("processDefinitionId")
private String processDefinitionId = null;
@JsonProperty("businessKey")
private String businessKey = null;
@JsonProperty("startedAt")
private OffsetDateTime startedAt = null;
@JsonProperty("endedAt")
private OffsetDateTime endedAt = null;
@JsonProperty("durationInMs")
private Integer durationInMs = null;
@JsonProperty("startActivityDefinitionId")
private String startActivityDefinitionId = null;
@JsonProperty("endActivityDefinitionId")
private String endActivityDefinitionId = null;
@JsonProperty("startUserId")
private String startUserId = null;
@JsonProperty("deleteReason")
private String deleteReason = null;
//constructors and setters+getters
}
Here is the call:
ResponseEntity<Process> responseModel = restTemplate.exchange("http://localhost:8062/processes", HttpMethod.POST, httpEntity, Process.class);
The problem is that i've tried a few methods like ignoring the OffsetDateTime properties or trying to change the format of that date but it will throw this error:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `org.threeten.bp.OffsetDateTime` (no Creators, like default construct, exist): no String-argument constructor/factory method to deserialize from String value ('2019-10-04T13:20:29.315Z')
Or it will return null :( What would be a good solution to solve this?
The error states it cannot construct instance of org.threeten.bp.OffsetDateTime. You need to use
java.time.offsetdatetime
Then in your model you can format it whatever way you like e.g.
@JsonProperty("endedAt") //this line is not needed when it is the same as the instance variable name
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd@HH:mm:ss.SSSZ")
private OffsetDateTime endedAt;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With