I have a simple POJO :
public class Test {
private String id;
private boolean asString;
// getters and setters
@JsonValue
public Object getValue() {
if (asString) {
return id;
}
// I want to use the default behavior of Jackson but i don't know what to do here
}
}
As you can see, i'm trying to use @JsonValue to make the following behavior :
- If
asString
istrue
, i want to serialize my object as a simple string. - If
asString
isfalse
, i want to serialize my object with the default behavior of Jackson. But i don't know how to do this.
I also tried to make a custom serializer, but i can't reach the "default serializer" of Jackson and call it.
How can i achieve this ? I want to serialize my object as a string on a certain condition but i want to back on the default behavior of Jackson if i want to.