【问题标题】:Cannot deserialize String to Java object无法将字符串反序列化为 Java 对象
【发布时间】:2020-04-08 13:08:44
【问题描述】:

(数据类)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;
}

(数据类)Entities.java

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

我试图运行这个语句:

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

我得到了这个错误:

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)

我已经输入了@JsonDeserializeimplements Serializable 我错过了什么?

【问题讨论】:

  • 尝试为实体类提供@NoArgsConstructor
  • 谢谢,成功了

标签: java serialization jackson lombok


【解决方案1】:

尝试为实体类提供@NoArgsConstructor。这应该可以。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-02-03
  • 2021-04-27
  • 2021-01-16
  • 2018-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多