Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoSuchFieldError: ACCEPT_CASE_INSENSITIVE_VALUES

I have a Spring Boot 2 project. The model is

@Entity
@SequenceGenerator(name = "climate_gen", sequenceName = "climate_gen", initialValue = 100)
public class Climate {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "climate_gen")
    private long id;

    private float temperature;
    private float humidity;
    @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd'T'HH:mm:ss")
    private LocalDateTime date;
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "location_id", nullable = false)
    private Location location;

The database has default records and using curl gets those records. But if I try to post

curl -H "Authorization: Bearer $TOKEN" -k -w "\n" -X POST -d '{"temperature":15.3,"humidity":65.4,"date":"2019-12-17T11:51:00","location":{"id":1}}' -H "Content-Type: application/json" https://mint191:8453/api/v1/climates

{"timestamp":"2019-12-18T13:53:22.473+0000","status":500,"error":"Internal Server Error","message":"ACCEPT_CASE_INSENSITIVE_VALUES","path":"/api/v1/climates"}

And the log output is

2019-12-18 13:53:42.056 ERROR 11401 --- [nio-8453-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchFieldError: ACCEPT_CASE_INSENSITIVE_VALUES] with root cause

java.lang.NoSuchFieldError: ACCEPT_CASE_INSENSITIVE_VALUES at com.fasterxml.jackson.datatype.jsr310.deser.JSR310DateTimeDeserializerBase.acceptCaseInsensitiveValues(JSR310DateTimeDeserializerBase.java:126) ~[jackson-datatype-jsr310-2.10.1.jar!/:2.10.1] at com.fasterxml.jackson.datatype.jsr310.deser.JSR310DateTimeDeserializerBase.createContextual(JSR310DateTimeDeserializerBase.java:86) ~[jackson-datatype-jsr310-2.10.1.jar!/:2.10.1]

I have several other models that are made of Strings and references. These all create with no problem.

Having googled around, I possibly have to use ObjectMapper and enable the ACCEPT_CASE_INSENSITIVE_VALUE feature. If so, do I have to set this at the service level? Controller? Model?

But in a more general context, what is actually happening here? What is jackson complaining about and why this model and not others?

Finally, because none of the fields are not null, I tried posting a series of requests, each with a afield missing. In each case, same result.

Regards,

like image 797
John Avatar asked Dec 18 '19 14:12

John


1 Answers

This is due to jackson library version incompatibility. For example jackson-core's version might be different than that of jackson-databind. Run

mvn dependency:tree -Dverbose

to findout jackson versions to resolve version incompatibility.

Refer this - https://github.com/FasterXML/jackson-modules-java8/issues/81

like image 66
charybr Avatar answered Oct 29 '22 14:10

charybr