FasterXML 中的 UnrecognizedPropertyException
UnrecognizedPropertyException in FasterXML
当我使用 fasterXML 将其转换为 POJO 时,我读取了字符串 "{"name":"John","timestamp":"2020-08-14T11:47:52.297194Z"}"
,但出现以下异常,
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "timestamp" (class com.job.model.Person), not marked as ignorable (2 known properties: "name", "timeStamp"])
我的 POJO 是,
@Data
@NoArgsConstructor
@Table(keyspace = "keyspace", name = "testTable")
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "name")
private String name;
@Column(name = "timeStamp")
//@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "UTC") // Tried with this no luck.
private Instant timeStamp;
}
我从下面添加了所需的依赖项 url,
https://github.com/FasterXML/jackson-modules-java8,还有
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.0</version>
</dependency>
ObjectMapper objectMapper = JsonMapper.builder()
.addModule(new ParameterNamesModule())
.addModule(new Jdk8Module())
.addModule(new JavaTimeModule())
.build();
已注册。
Json 有 timestamp
而 pojo 有 timeStamp
。在 pojo 中重命名或使用 @JsonProperty("timestamp")
@JsonProperty("timestamp")
private Instant timeStamp;
当我使用 fasterXML 将其转换为 POJO 时,我读取了字符串 "{"name":"John","timestamp":"2020-08-14T11:47:52.297194Z"}"
,但出现以下异常,
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "timestamp" (class com.job.model.Person), not marked as ignorable (2 known properties: "name", "timeStamp"])
我的 POJO 是,
@Data
@NoArgsConstructor
@Table(keyspace = "keyspace", name = "testTable")
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "name")
private String name;
@Column(name = "timeStamp")
//@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "UTC") // Tried with this no luck.
private Instant timeStamp;
}
我从下面添加了所需的依赖项 url,
https://github.com/FasterXML/jackson-modules-java8,还有
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.0</version>
</dependency>
ObjectMapper objectMapper = JsonMapper.builder()
.addModule(new ParameterNamesModule())
.addModule(new Jdk8Module())
.addModule(new JavaTimeModule())
.build();
已注册。
Json 有 timestamp
而 pojo 有 timeStamp
。在 pojo 中重命名或使用 @JsonProperty("timestamp")
@JsonProperty("timestamp")
private Instant timeStamp;