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

Deserialize failed when using referencing and the object does not have an empty constructor #4433

Open
1 task done
Ferioney opened this issue Mar 16, 2024 · 1 comment
Open
1 task done
Labels
to-evaluate Issue that has been received but not yet evaluated

Comments

@Ferioney
Copy link

Ferioney commented Mar 16, 2024

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

I found a strange issue when trying to deserialize a specific object with the next conditions:

  • this object has a field (property) with the same object type (like children or parent):
class Cat  {
    //Can have reference to the same type
    private Cat children;
   
    //Can have reference to the same type (like parent object)
    private Cat parent;
}
  • object is "generic" (I use JsonTypeInfo and implement some interface)
  • using JsonIdentityInfo
  • this object has all args constructor
  • this object does not have an empty constructor

In that case I have an exception:

java.lang.RuntimeException: com.fasterxml.jackson.databind.deser.UnresolvedForwardReference: Could not resolve Object Id [1] (for [simple type, class org.test.ser.domain.Dog]).
 at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 9, column: 16] (through reference chain: org.test.ser.domain.Dog["children"]->org.test.ser.domain.Dog["parent"])

If I add an empty contractor to this object it works fine. But in my case I can not change this object (its coming from library)

Version Information

2.16.2

Reproduction

here a detail example: test-generic-ser

Generic interface with JsonIdentityInfo and JsonTypeInfo: Animal.java
Dog implementation without empty constructor: Dog.java
Cat implementation with empty constructor: Cat.java

Dog tests:

  1. Object does not have children object:
    json
    test works: canDeserializeWhenNoChildren
  2. object has children object:
    json
    test failed: canNotDeserializeWhenHasChildren

Cat test (object with empty constructor):
json
test works: canDeserializeWhenHasChildrenAndEmptyConstructor

ObjectMapper configuration (I used the same objectMapper to generate json): ObjectMapper
In additional I use jackson-module-parameter-names: maven param names dependency

Expected behavior

No response

Additional context

No response

@Ferioney Ferioney added the to-evaluate Issue that has been received but not yet evaluated label Mar 16, 2024
@JooHyukKim
Copy link
Member

Thank you for the reproduction! 👍🏼 Very specific, but could it be possible to share here a minimal reproduction that can fit into this issue? Maybe like one here #4409.

This is to minimize overhead for anyone passing by to identify the problem and maybe easily share a solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to-evaluate Issue that has been received but not yet evaluated
Projects
None yet
Development

No branches or pull requests

2 participants