Skip to content

Reproduction of a serialization issue when using Spring Data REST with Hibernate

Notifications You must be signed in to change notification settings

shakuzen/jackson-hibernate-serialization-repro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serialization issue reproduction

The JUnit test contained in JacksonHibernateProxyReproApplicationTests reproduces the issue. This may be the same issue described in FasterXML/jackson-datatype-hibernate#77 or this mentioned StackOverflow question.

When using Hibernate with Spring Data REST, Hibernate proxies of entities will not be serialized properly.

The PersistentEntityJackson2Module will wrap entities in a org.springframework.hateoas.Resource class. When the Resource's content field contains a Hibernate proxy, it is serialized even though it should be unwrapped as it is marked with @JsonUnwrapped.

Expected serialization:

{
  "items": [
    {
      "itemDetails": [
        {
          "extras": [
            {
              "type": "something"
            }
          ],
          "status": "reserved"
        }
      ],
      "something": "something"
    }
  ],
  "something": "something",
  "_links": {
    "self": {
      "href": "http://localhost:8080/reservations/9d0bab3c-8801-43b2-a15e-d7d6bfc08116"
    },
    "reservation": {
      "href": "http://localhost:8080/reservations/9d0bab3c-8801-43b2-a15e-d7d6bfc08116"
    }
  }
}

Actual serialization (notice the content field):

{
  "items": [
    {
      "content": {
        "itemDetails": [
          {
            "extras": [
              {
                "type": "something"
              }
            ],
            "status": "reserved"
          }
        ],
        "something": "something"
      }
    }
  ],
  "something": "something",
  "_links": {
    "self": {
      "href": "http://localhost:8080/reservations/9d0bab3c-8801-43b2-a15e-d7d6bfc08116"
    },
    "reservation": {
      "href": "http://localhost:8080/reservations/9d0bab3c-8801-43b2-a15e-d7d6bfc08116"
    }
  }
}

About

Reproduction of a serialization issue when using Spring Data REST with Hibernate

Topics

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published