当我使用"{"name":"John","timestamp":"2020-08-14T11:47:52.297194Z"}"将字符串fasterXML转换为POJO时,我会看到以下异常,
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "timestamp" (class com.job.model.Person), not marked as ignorable (2 known properties: "name", "timeStamp"])我的波乔是,
@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();都是注册的。
发布于 2020-08-14 12:41:56
Json拥有timestamp,而pojo拥有timeStamp。要么在pojo中重命名,要么使用@JsonProperty("timestamp")
@JsonProperty("timestamp")
private Instant timeStamp; https://stackoverflow.com/questions/63412945
复制相似问题