I have following DTOs:
@Value
public class PracticeResults {
@NotNull
Map wordAnswers;
}
@Value
public class ProfileMetaDto {
In case you have some final fields within your class and you would rather have Object creator to use specific constructor to deserialize your POJO along with @Data
annotation, I suggest annotating the constructor with @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
and concrete required constructor parameters with @JsonProperty("
. The example can be seen below:
package test.model;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.Date;
@Data
public class KafkaEventPojo {
private final String executionId;
private final String folder;
private final Date created_at;
private Date updated_at;
// ... other params
/**
* Instantiates a new Kafka event pojo.
*
* @param executionId the execution or flow id of the event lifecycle
* @param folder the folder to be retrieved
*/
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public KafkaEventPojo(@JsonProperty("executionId") String executionId, @JsonProperty("folder") String folder) {
this(executionId, folder, new Date(System.currentTimeMillis()));
}
private KafkaEventPojo(String executionId, String folder, Date date) {
this.executionId = executionId;
this.folder = folder;
this.created_at = date;
this.updated_at = date;
}
// ... other logic
}