I have a simple controller that return a User object, this user have a attribute coordinates that have the hibernate property FetchType.LAZY.
When I try to get this
I tried this, and worked:
// custom configuration for lazy loading
public static class HibernateLazyInitializerSerializer extends JsonSerializer {
@Override
public void serialize(JavassistLazyInitializer initializer, JsonGenerator jsonGenerator,
SerializerProvider serializerProvider)
throws IOException, JsonProcessingException {
jsonGenerator.writeNull();
}
}
and configure mapper:
mapper = new JacksonMapper();
SimpleModule simpleModule = new SimpleModule(
"SimpleModule", new Version(1,0,0,null)
);
simpleModule.addSerializer(
JavassistLazyInitializer.class,
new HibernateLazyInitializerSerializer()
);
mapper.registerModule(simpleModule);