In one of our projects we use a java webapp talking to a MongoDB instance. In the database, we use DBRefs to keep track of some object relations. We (de)seriali
Use a custom JSONSerializer and apply your logic in the serialize method:
public static class FooReference {
public DBRef foo;
@JsonSerialize(using = CustomSerializer.class)
public Foo getFoo() {
return foo.fetch();
}
}
public class CustomSerializer extends JsonSerializer