Search code examples
jacksonfasterxml

UnrecognizedPropertyException in FasterXML


I read String "{"name":"John","timestamp":"2020-08-14T11:47:52.297194Z"}" when i convert it into POJO using fasterXML i get the below exception,

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "timestamp" (class com.job.model.Person), not marked as ignorable (2 known properties:  "name", "timeStamp"])

My POJO is,


@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; 

}

I added the required dependency from the below url,

https://github.com/FasterXML/jackson-modules-java8, and also

 <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();

is registered.


Solution

  • Json has timestamp while pojo has timeStamp. Either rename in pojo or use @JsonProperty("timestamp")

    @JsonProperty("timestamp")
    private Instant timeStamp;