0

I'm using Spring Data ElasticSearch v4.2.x, my data was returned in JSON String.

Here is the problem,I tried to parse JSON string to Object,then I got "java.lang.NullPointerException".I have a Date field with these annotations,I'm sure this field is causing this problem:

    @Field(type = FieldType.Keyword, name = "created_at", format = DateFormat.basic_date_time, pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createdAt;
1
  • It won't have any problem with Spring Data ElasticSearch v4.0.x Commented Nov 30, 2021 at 8:16

1 Answer 1

1

You defined the type as FieldType.Keyword, you would need FieldType.Date.

The @JsonFormat annotation is ignore by Spring Data Elasticsearch.

And please, stop using the old java.util.Date class and use the classes from java.time instead, they are now available since Java 8.

Sign up to request clarification or add additional context in comments.

1 Comment

I found that it was my serialization configuration problem, but your suggestions still help me a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.