2

I am using jackson 2.4.2 to mapp some hibernate results, because the hibernate object can be quite complex, the problem I am receiving is, I have a list of hibernate object, some of them may refer to the same object, thus jackson only mapp the object once, and all other objects are only mapped as an id. I don't want it behave like this and want it to write objects as object no matter if it is parse in other object or not.

user2412555
  • 1,055
  • 1
  • 16
  • 32
  • this post give 3 possibilities : https://stackoverflow.com/questions/28393599/autowiring-in-jsondeserializer-springbeanautowiringsupport-vs-handlerinstantiat – user1568220 Aug 02 '17 at 20:52

1 Answers1

0

Show us some code and especially your class structure and json/xml or whatever results.

But i think the problem is that you are only saving object_id as Integer and not as object.

Wrong:

public class Foo {
    private String name;
    private Integer foo_id;
}

Correct:

public class Foo {
    private String name;
    private Foo foo;
}
q0re
  • 1,401
  • 19
  • 32
  • I think the problem is I am using hibernate, I have two hibernate object A and B, A have a field refer to object B, and B has a field that is annotated with @id, so when I get a db result from hibernate, I may have several object A refer to the same object B, the first object A that refers to object B parses correctly, but othe object A refer to the same object B only have an ID instead of the entire object. little difficult to show code. but what I am basically doing is create an ObjectMapper and then just using writeValueAsString on the List of objects I got from hibernate. – user2412555 Jan 26 '15 at 09:55
  • Hmm, what you can do is fetch object B and then a list of object A refer to B. Now you can loop trough the list and assign the relation manually. But i have no idea why the other obejcts didnt get parsed correctly.. – q0re Jan 26 '15 at 12:40
  • It seems because hibernate gets from cache, so all Object B that have the same id is just reference to the first one, and Jackson being smart, only parse id of reference objects. I wonder you can turn off reference id parsing in jackson and always parse complete objet. – user2412555 Jan 26 '15 at 12:45