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

Impossible to deserialize custom Throwable sub-classes that do not have single-String constructors #4071

Closed
1 task done
Pass-Kal opened this issue Aug 8, 2023 · 4 comments · Fixed by #4072
Closed
1 task done
Labels
to-evaluate Issue that has been received but not yet evaluated

Comments

@Pass-Kal
Copy link

Pass-Kal commented Aug 8, 2023

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

An UnrecognizedPropertyException is thrown on fields "message" and/or "suppressed" while deserializing a custom exception.
(since correction #3497)

Workaround : adding ".configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)" (but with operationnal impact)

Version Information

2.14+

Reproduction

public class CustomException extends Exception{
public CustomException (){
super();
}
}

String json = JsonMapper.builder().build().writeValueAsString(new CustomException());
JsonMapper.builder().build().readValue(json, CustomException.class);

==> UnrecognizedPropertyException

Expected behavior

Deserialization is possible without disabling FAIL_ON_UNKNOWN_PROPERTIES

Additional context

Since f27df63
with the removal of "builder.addIgnorable("localizedMessage");" and "builder.addIgnorable("suppressed");" In class [BeanDeserializerFactory.java] (line 452 and line 454)

@Pass-Kal Pass-Kal added the to-evaluate Issue that has been received but not yet evaluated label Aug 8, 2023
@JooHyukKim
Copy link
Member

It seems what the commit f27df63 tried to solve in #3497 did not intend change of behavior decribed here.

Though it needs review by @cowtowncoder, #4072 might solve the problem.

@Pass-Kal
Copy link
Author

Pass-Kal commented Aug 9, 2023

Thanks for this fix.

I think it was not the intention but the removed lines have seemed unnecessary as it would have to be assumed by the ThrowableDeserializer.

For some reasons, I have the same problem on some other custom exceptions with the property "suppressed" (the getter is "getSuppressed" but the fied is "suppressedExceptions" and it was also ignored by the removed code in f27df63)

@JooHyukKim
Copy link
Member

Thanks for this fix.

Np! Also, I only made a "possible" fix :)) I still probably need more time to figure out Jackson's behavior on Throwable's or its sub-classes.

For some reasons, I have the same problem on some other custom exceptions with the property "suppressed" (the getter is "getSuppressed" but the fied is "suppressedExceptions" and it was also ignored by the removed code in f27df63)

@Pass-Kal Could you also share the example case here? What is also possible is that #4072 will either

  • fix a problem (possible regression)
  • or revert back some other intended behavioral change made by f27df63

@cowtowncoder
Copy link
Member

I merged #4072, which should handle message case.

@cowtowncoder cowtowncoder changed the title Impossible to deserialize a class wich extends Throwable without desabling FAIL_ON_UNKNOWN_PROPERTIES Impossible to deserialize custom Throwable sub-classes that do not have single-String constructors Aug 20, 2023
cowtowncoder added a commit that referenced this issue Aug 20, 2023
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

Successfully merging a pull request may close this issue.

3 participants