Json有
当我使用fasterXML将字符串"{"name":"John","timestamp":"2020-08-14T11:47:52.297194Z"}"
转换为POJO时,我读取了它,得到了以下异常
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();
已注册。
timestamp
,而pojo有timeStamp
。在pojo中重命名或使用@JsonProperty("timestamp")
@JsonProperty("timestamp")
private Instant timeStamp;