Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When serialzing with DefaultTyping and hibernate, it is impossible to deserialize some models #90

Open
kmorozov opened this issue Apr 21, 2016 · 1 comment

Comments

@kmorozov
Copy link

Consider a class that looks like this:

class BeanOne
{
  int id;

  @OneToMany(fetch = FetchType.LAZY)
  List<BeanTwo> links;
}

class BeanTwo
{
  int id;
}

BeanOne and BeanTwo are managed by Hibernate via JPA. If I set DefaultTyping.JAVA_LANG_OBJECT on my Object mapper, and then serialize the bean, the output will depend on if i loaded the bean from the Database.

In the case where the bean is not loaded from the database the json would look like this:

{
  "id": 1,
  "links": [
    {
      "id": 2
    },
    {
      "id": 3
    }
  ]
}

In the case where the bean is loaded from the database the json would look like this:

{
  "id": 1,
  "links": [
    [
      "com.example.BeanTwo",
      {
        "id": 2
      }
    ],
    [
      "com.example.BeanTwo",
      {
        "id": 3
      }
    ]
  ]
}

Now, in principle, everything is working as intended, because Hibernate replaces the Lists with PersistentBags which have a raw-type List inside. Jackson will thus see the raw array and add types like the friendly serializer that it is. However, when I try to deserialize that json, it fails because jackson does not expect type information for the 'links' field since that field has an explicit type.

I am not sure if this qualifies as a bug or a feature request, but I think that there should be some way to reconcile these two features.

@MichaelSp
Copy link

wow, still not solved? Has anyone found a working way to handle this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants