0

I have a problem when trying to get an object with multiple many to one relationships. I have a table Flight which has its Airport Destination/Origin and Airline. The Airport has its Country and the Airline has its Country. The problem is when the Country for the Airport and the Airline is the same. Jackson only writes one Country as an object, and for the other just writes its ID. Here is JSON that I got:

[{
"flightId": 1,
"airportByFkAirportOrigin": {
    "airportId": 1,
    "country": {
        "countryId": 1,
        "name": "Croatia"
    },
    "city": "Zagreb",
    "name": "Pleso"
},
"airportByFkAirportDest": {
    "airportId": 2,
    "country": {
        "countryId": 2,
        "name": "Germany"
    },
    "city": "Frankfurt",
    "name": "Flughafen Frankfurt am Main"
}
"airline": {
    "airlineId": 1,
    "country": 1,
    "name": "Croatia Airlines",
    "callsign": "Croatia",
}
"date": "2015-05-20",
"timeDepartScheduled": "21:00",
"timeArriveScheduled": "22:30",
}]

As you can see in Airport Origin the Country object named Croatia is written and the same with Airport Destination object name Germany is written. But for the Airline Country object again should be Croatia but for some reason only its ID is written. And just to be clear fetching is set to EAGER on both Country objects in Airport and in Airline and when debugging I can see that hibernates returns Country object for all of them including Airline, but for some reason Jackson decides to remove the one in Airline when converting to JSON. Anybody knows why?

EDIT: I've found the same issue here but with no solution. Somebody, pls?

Community
  • 1
  • 1
Mario Rudman
  • 1,899
  • 2
  • 14
  • 18

1 Answers1

0

The reason Jackson wrote the whole object only for the first appearance of that object is @JsonIdentityInfo annotation which I used for handling cyclic object graphs.

Mario Rudman
  • 1,899
  • 2
  • 14
  • 18