Failed to instantiate com.fasterxml.jackson.databind.node.ObjectNode using the NO_CONSTRUCTOR constructor with arguments in MongoDB

enter image description here I use JsonNode to get data from any kind of jason format and save it in mongoDb. But when retrieving data from mongoDB, this is an error, as shown below.

Failed to instantiate com.fasterxml.jackson.databind.node.ObjectNode using constructor NO_CONSTRUCTOR with arguments

Below is my domain class

 public class Profiler { @Id private String id; @Field("email") private String email; @Field("profiler") private Map<String,JsonNode> profiler; public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public Map<String, JsonNode> getProfiler() { return profiler; } public void setProfiler(Map<String, JsonNode> profiler) { this.profiler = profiler; } public Profiler(String email,Map<String,JsonNode> profiler){ this.email=email; this.profiler = profiler; } @JsonCreator public Profiler(@JsonProperty("_id")String id,@JsonProperty("email")String email,@JsonProperty("profiler")Map<String,JsonNode> profiler){ this.id=id; this.email=email; this.profiler = profiler; } public Profiler(String id){ this.id=id; } public Profiler(Map<String,JsonNode> profiler){ this.profiler = profiler; } public Profiler(){ } } public interface ProfilerRepository extends MongoRepository<Profiler, String>{ public Profiler findOneByEmail(String email); } 

And my controller call is below, and I get an error on this line.

 Profiler profile=profileService.findOneByEmail(email); 
+5
source share
2 answers

I made these changes and worked as expected.

 Map<String, Object> profile; 
+4
source

This problem occurs because the com.fasterxml.jackson.databind.node.ObjectNode class com.fasterxml.jackson.databind.node.ObjectNode not have a default constructor (without an argument constructor), and Jackson expects a default constructor.

Linked post refers to azerafati answer

The problem can be solved if you define the profiler field as static in the domain class.

 private static Map<String, JsonNode> profiler; 

Note that static fields have their own limitations and problems. I can assure that this will resolve the above exception. However, this may not be the most suitable solution.

+1
source

Source: https://habr.com/ru/post/1260194/