Aussawin Kaokum
Aussawin Kaokum

Reputation: 13

Cannot deserialize String to Java object

(Data class) Entity.java

@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class Entity implements Serializable {
    private String id;
    private String name;
    private String status;
    private ZonedDateTime registrationDatetime;
    private ZonedDateTime updatedDatetime;
    private ZonedDateTime createdDatetime;
}

(Data class) Entities.java

@Data
@AllArgsConstructor
@JsonDeserialize
public class Entities implements Serializable {
    private List<Entity> entities;
}

I tried to run this statement:

TypeReference<ResponseModel<Entities>> typeReference = new TypeReference<ResponseModel<Entities>>() {};
ResponseModel<Entities> response = objectMapper.readValue(result.getResponse().getContentAsString(), typeReference);

And I got this error:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `model/Entities` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)

I already put @JsonDeserialize and also implements Serializable what did I miss?

Upvotes: 1

Views: 626

Answers (1)

Nandu Raj
Nandu Raj

Reputation: 2110

Try giving @NoArgsConstructor also for Entities class. This should work.

Upvotes: 1

Related Questions