When I try to post new object with post method. RequestBody could not recognize contentType. Spring is already configured and POST could work with others objects, but not th
specify @JsonProperty in entity class constructor like this.
......
......
......
@JsonCreator
public Location(@JsonProperty("sl_no") Long sl_no,
@JsonProperty("location")String location,
@JsonProperty("location_type") String
location_type,@JsonProperty("store_sl_no")Long store_sl_no) {
this.sl_no = sl_no;
this.location = location;
this.location_type = location_type;
this.store_sl_no = store_sl_no;
}
.......
.......
.......
I had this problem when using java 9+ modules. I had to open
the module in order for the com.fasterxml.jackson.databind
to access the objects with reflection. Alternatively you could only open the package where the models are located if you have one.
In my case I had two Constructors in the bean and I had the same error. I have just deleted one of them and now the issue is fixed!
I had the same issue when I used this as a foreign key.
@JsonBackReference
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.DETACH},fetch = FetchType.EAGER)
@JoinColumn(name = "user_id")
private User user;
Then I removed @JsonBackReference
annotation. After that above issue was fixed.
Really! after spending 4 hours and insane debugging I found this very strange code at com.fasterxml.jackson.databind.deser.DeserializerCache
if (deser == null) {
try {
deser = _createAndCacheValueDeserializer(ctxt, factory, type);
} catch (Exception e) {
return false;
}
}
Ya, the problem was double setter.
I had the same issue. Root cause was using custom deserializer without default constructor.