I am trying to deserialize a object ref ($ref) using ObjectMapper.
public class Foo {
@JsonProperty("bar")
private Bar bar;
@JsonProperty("bar")
public Bar getBar() {
return bar;
}
@JsonProperty("bar")
public void setBar(Bar bar) {
this.bar = bar;
}
}
test.json This is the json file I am trying to deserialize. Is this is the correct way to refer to a object/json reference?
{
"bar": {"$ref": "/bar.json"}
}
Deserializer.java
ObjectMapper objectMapper = new ObjectMapper();
//load class
URL url = Deserializer.class.getClassLoader().getResource("test.json");
//deserialize
objectMapper.readValue(url, Foo.class);
the result creates a Foo pojo with additional property of "bar": ""$ref": "/bar.json"" rather than deserializing it. Do I need to implement the deserialize interface and manually deserialize the node?