Let's say I have the following classes:
public class MyClass {
private Test t;
public MyClass() {
t = new Test(50);
}
}
public class Test {
private int test;
public Test(int test) {
this.test = test;
}
public String toCustomString() {
return test + "." + test;
}
}
When Jackson serializes an instance of MyClass
, it will look like the following:
{"t":{"test":50}}
Is there any annotation I can put in the Test
class to force Jackson to invoke the toCustomString()
method whenever serializing a Test
object?
I'd like to see one of the following outputs when Jackson serializes an instance of MyClass
:
{"t":"50.50"}
{"t":{"test":"50.50"}}