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

Add descriptive exception for attempts to use @JsonWrapped via Creator parameter #265

Closed
cowtowncoder opened this issue Jul 17, 2013 · 6 comments
Milestone

Comments

@cowtowncoder
Copy link
Member

cowtowncoder commented Jul 17, 2013

@JsonUnwrapped does not currently work with creator parameters; both because name linkage is needed (despite not being used), but also because unwrapped-handler absolutely requires existence of POJO to assign reconstructed value to -- which can not be done without Creator having access. So basic chicken-and-egg problem.

While this is theoretically (and hopefully ultimately) solvable problem, at this point (jackson 2.9 development) it is better to add clear exception to indicate the issue, instead of producing a confusing and misleading exception like currently happens.

@davispw
Copy link

davispw commented Aug 23, 2013

Thought I'd paste the relevant exception here, to help in finding this issue:

java.lang.IllegalStateException: Method should never be called on a com.fasterxml.jackson.databind.deser.CreatorProperty
    at com.fasterxml.jackson.databind.deser.CreatorProperty.set(CreatorProperty.java:182)
    at com.fasterxml.jackson.databind.deser.CreatorProperty.deserializeAndSet(CreatorProperty.java:165)
    at com.fasterxml.jackson.databind.deser.impl.UnwrappedPropertyHandler.processUnwrapped(UnwrappedPropertyHandler.java:61)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeUsingPropertyBasedWithUnwrapped(BeanDeserializer.java:648)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeWithUnwrapped(BeanDeserializer.java:478)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:271)

@LukaszWiktor
Copy link

+1

@weaselmetal
Copy link

+1 ... I think it should be possible to remove any suffix/prefix that was added when unwrapping and call a JsonCreator with the remaining / cleaned field names. No?

@cowtowncoder
Copy link
Member Author

@weaselmetal You are welcome to check how easy that would be to do. Unfortunately I won't have time to work on this issue any time soon.

@cowtowncoder
Copy link
Member Author

Ok. After first falsely concluding that this could work, I am realizing that the way unwrapped properties are implemented, they will NOT be supportable as constructor-backed creator properties without major rewrite.

So. What I will do for 2.9 is to add checks so that attempts to do this should fail earlier with more descriptive error message. I will also remove code that tries to handle the case since it can not work as designed: Creator expects fully resolved unwrapped values, but unwrapped-value resolved can only run after Creator has created the POJO to assign values to.

But I will create a new issue for potentially doing said major rewrite to add support, since it is theoretically doable. Just not with small/medium incremental changes.

@cowtowncoder cowtowncoder changed the title Support @JsonUnwrapped with @JsonCreator (if possible) Add descriptive exception for attempts to use @JsonWrapped via Creator parameter Dec 2, 2016
@cowtowncoder cowtowncoder added this to the 2.9.0 milestone Dec 2, 2016
@cowtowncoder
Copy link
Member Author

For 2.19, support is actually being added -- after all these years! See #1467 for details.

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

4 participants