I am trying to serialize a string to java object in scala codebase. I am not sure if this is even compatible, but the same code works for scala case class object but not for java pojo.
Java Pojo :
@Data
public class JobConfigTest {
@JsonProperty("name")
private String name;
public JobConfigTest(String name) {
this.name = name;
}
}
Scala object :
case class job (name : String)
Serialition Code :
val str : String = "{\"name\": \"hotel\"}";
val mapper = new ObjectMapper()
mapper.registerModule(DefaultScalaModule)
This works :
val a1 = mapper.readValue(str, classOf[job]
This gives error :
val a2 = mapper.readValue(str, classOf[JobConfigTest])
Error log :
Unrecognized field "name" (class com.content.datavalidation.config.JobConfigTest), not marked as ignorable (37 known properties: "endWith", "succeed", "be", "regex", "startWith", "defined", "matchPattern", "empty", "not", "contain", "stackDepth", "styleName", "key", "writable", "a", "subjectWithAfterWordRegistrationFunction", "length", "they", "it", "an", "typeCheck", "readable", "value", "compile", "exist", "decided", "subjectRegistrationFunction", "theSameInstanceAs", "assertionsHelper", "size", "fullyMatch", "after", "include", "behave", "determined", "sorted", "have"])
at [Source: (String)"{"name": "Hotel"}"; line: 1, column: 11] (through reference chain: com.content.datavalidation.config.JobConfigTest["name"])
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "name" (class com.content.datavalidation.config.JobConfigTest), not marked as ignorable (37 known properties: "endWith", "succeed", "be", "regex", "startWith", "defined", "matchPattern", "empty", "not", "contain", "stackDepth", "styleName", "key", "writable", "a", "subjectWithAfterWordRegistrationFunction", "length", "they", "it", "an", "typeCheck", "readable", "value", "compile", "exist", "decided", "subjectRegistrationFunction", "theSameInstanceAs", "assertionsHelper", "size", "fullyMatch", "after", "include", "behave", "determined", "sorted", "have"])
at [Source: (String)"{"name": "Hotel"}"; line: 1, column: 11] (through reference chain: com.content.datavalidation.config.JobConfigTest["name"])