I have a model class that I want to wrap for a REST service for output.
public class Model {
private String name;
}
public class Wrapper {
private Model model;
private Date modifiedDate;
}
public class Converter extends StdConverter<Model, Wrapper> {
@Override
public Wrapper convert(Model model) {
return new Wrapper(model, new Date());
}
}
When the output is json along the lines
{
"model": {
"name" : "dave"
},
"date": "tuesday"
}
The problem is that it is stuck in a loop. Constantly trying to serialize the model nested inside it.
I tried adding @JsonSerialize(converter = Converter.class)
and installing module.addSerializer(Model.class, new StdDelegatingSerializer(new Converter()));in my mapper object, but get the same results every time.
Using jackson 2.8.5
source
share