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

Type id not exposed for JsonTypeInfo.As.EXTERNAL_PROPERTY even when visible set to true #1288

Closed
libetl opened this issue Jul 6, 2016 · 8 comments
Milestone

Comments

@libetl
Copy link
Contributor

libetl commented Jul 6, 2016

Jackson : 2.8.0.rc2

Hello,

I have these following jsons to deserialize, with a type property ("form_of_payment") located outside a polymorphic class ("payment_details") :

    {"form_of_payment":"INDIVIDUAL_CREDIT_CARD","payment_details":{"card_holder_first_name":"John", "card_holder_last_name":"Doe",  "number":"XXXXXXXXXXXXXXXX", "expiryDate":"MM/YY"}
    {"form_of_payment":"INSTRUMENTED_CREDIT_CARD","payment_details":{"payment_instrument_id":"00000000-0000-0000-0000-000000000000", "name":"Mr John Doe encrypted credit card"}

I have to use the @JsonTypeInfo annotation on the PaymentDetails class, to inform Jackson that there are several kinds of PaymentDetails.

The include must be a include = JsonTypeInfo.As.EXTERNAL_PROPERTY.

Once the TypeResolver has done his job, the JsonTypeInfo is removed from the feed, which annoys me a lot (the "form_of_payment" also must be read for business purposes). If it is an EXTERNAL_PROPERTY, there is no way to restore it (it works with PROPERTY, but the JsonTypeInfo must be inside the same object)

Can you add a spare visibility property to the @JsonTypeInfo to find it in the parent object ?
Here is a link to where it happens : https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/AsArrayTypeDeserializer.java#L99

Thanks.

(I have seen the #408 issue BTW)

@cowtowncoder
Copy link
Member

cowtowncoder commented Jul 6, 2016

Did you check the javadocs? If so, wouldn't visible:

http://fasterxml.github.io/jackson-annotations/javadoc/2.7/com/fasterxml/jackson/annotation/JsonTypeInfo.html#visible()

do what you ask? If not, why?

@libetl
Copy link
Contributor Author

libetl commented Jul 6, 2016

visible does not work with external_property

@cowtowncoder
Copy link
Member

@libetl issue #408 claims it does, so I'd need a unit test to prove otherwise to see when and how it does not work as expected, reproducible against either 2.8.0 or 2.7.5 (earlier branches are closed for development).

@libetl
Copy link
Contributor Author

libetl commented Jul 6, 2016

with pleasure. Give me some time to try that (going back home for the moment)

@libetl
Copy link
Contributor Author

libetl commented Jul 6, 2016

Please have a look at this failing test (I have cloned HEAD today) :
https://gist.github.com/libetl/9c6ec1820444370c3c55670058f57426

@cowtowncoder
Copy link
Member

@libetl thank you for reproduction. I hope to have a look at it soon.

@libetl
Copy link
Contributor Author

libetl commented Jul 11, 2016

I found out that this issue is closely linked to the builder deserialization.
I have updated my gist, with two versions of the same unmarshalling.
The first one (without builder) works, the second one fails.

@libetl
Copy link
Contributor Author

libetl commented Jul 11, 2016

NOW, I know.
The Jira JACKSON-831 correction on the BeanDeserializer was not applied on the BuilderBasedDeserializer (which appears to be a copy/paste).
Do you want me to submit a PR ?

cowtowncoder added a commit that referenced this issue Jul 11, 2016
#1288 applying JACKSON-831 on the BuilderBasedDeserializer
@cowtowncoder cowtowncoder changed the title I want to be able to recover the JsonTypeInfo even if it is an EXTERNAL_PROPERTY Type id not exposed for JsonTypeInfo.As.EXTERNAL_PROPERTY even when visible set to true Jul 12, 2016
@cowtowncoder cowtowncoder added this to the 2.8.1 milestone Jul 12, 2016
cowtowncoder added a commit that referenced this issue Jul 12, 2016
cowtowncoder added a commit that referenced this issue Jul 12, 2016
@libetl libetl closed this as completed Jul 12, 2016
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