Is it possible to override the name generated by jackson-datatype-hibernate Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS?
Currently it is serializing using full package name:
"client":{"com.test.domain.Client":1}
I want it to use id instead:
"client":{"id":1}
I am subclassing the ObjectMapper so maybe there is some method I can hook into
public class HibernateAwareObjectMapper extends ObjectMapper {
public HibernateAwareObjectMapper() {
Hibernate4Module hbm = new Hibernate4Module();
hbm.configure(Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS, true);
registerModule(hbm);
}
}
I have the same problem, I think it caused by
Hibernate
's proxy.I haven't a perfect solution recently, but you can solved it like this:
get the id, then create a new
com.test.domain.Client
object and set back to parent. then you will get"client": {"id":1,...}
Modify your entity, add one more id for just readable to the parent object, for example,
clientId
. Then you could avoid jackson to serialize the sub object. You will get{..., "clientId":1,...}
Hope some one can give more perfect solution.