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

@JsonTypeInfo does not work if the Type Id is an Integer value #1751

Closed
marvin-we opened this issue Aug 26, 2017 · 6 comments
Closed

@JsonTypeInfo does not work if the Type Id is an Integer value #1751

marvin-we opened this issue Aug 26, 2017 · 6 comments
Milestone

Comments

@marvin-we
Copy link

Hello together,

I am using the latest version of jackson (2.9.0) and I am trying to parse the following json:

[0,{"beneficiaries":[{"account":"esteemapp","weight":500}]}]

The first part of the array (0) is the id of the type of the second part of the array. To solve this I came up with the following configuration for the parent class:

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_ARRAY)
@JsonSubTypes({ @Type(value = CommentPayoutBeneficiaries.class, name = "0") })
public abstract class CommentOptionsExtension {

Using the snippet above causes the following Exception:

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (VALUE_NUMBER_INT), expected VALUE_STRING: need JSON String that contains type id (for subtype of eu.bittrade.libs.steemj.base.models.CommentOptionsExtension)
at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: java.util.ArrayList[0]->eu.bittrade.libs.steemj.base.models.SignedBlockWithInfo["transactions"]->java.util.ArrayList[9]->eu.bittrade.libs.steemj.base.models.Transaction["operations"]->java.util.ArrayList[1]->eu.bittrade.libs.steemj.base.models.operations.CommentOptionsOperation["extensions"]->java.util.ArrayList[0])
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
at com.fasterxml.jackson.databind.DeserializationContext.wrongTokenException(DeserializationContext.java:1485)
at com.fasterxml.jackson.databind.DeserializationContext.reportWrongTokenException(DeserializationContext.java:1260)
at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer._locateTypeId(AsArrayTypeDeserializer.java:151)
at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer._deserialize(AsArrayTypeDeserializer.java:96)
at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer.deserializeTypedFromObject(AsArrayTypeDeserializer.java:61)
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:254)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:287)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:244)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:127)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:287)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer._deserialize(AsArrayTypeDeserializer.java:116)
at com.fasterxml.jackson.databind.jsontype.impl.AsArrayTypeDeserializer.deserializeTypedFromObject(AsArrayTypeDeserializer.java:61)
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:254)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:287)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:244)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:127)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:287)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:285)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:244)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)
at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:136)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:287)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:285)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:244)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:3733)
... 28 more

It would be great if it would be possible to also use Integer values as an Id.

Thank you and best regards!

@volkert-fastned
Copy link

volkert-fastned commented Nov 25, 2022

Just ran into this same limitation, but with JsonTypeInfo.As.PROPERTY. Would be indeed be nice if this could be made more flexible.

@cowtowncoder cowtowncoder modified the milestones: 2.15.0, 2.14.0, 2.14.2 Nov 26, 2022
@cowtowncoder cowtowncoder changed the title @JsonTypeInfo does not work if the ID is an Integer value @JsonTypeInfo does not work if the Type Id is an Integer value Nov 26, 2022
@cowtowncoder cowtowncoder added 2.14 and removed 2.15 labels Nov 26, 2022
@cowtowncoder
Copy link
Member

@volkert-fastned Thanks for reminder -- I had somehow missed this one; turned out simple to improve handling as suggested.

@volkert-fastned
Copy link

Much appreciated! Thank you. Any ETA on the release of 2.14.2?

@cowtowncoder
Copy link
Member

@volkert-fastned No idea at this point. There are few fixes, and release process takes multiple hours. So unlikely to happen before 2023.

@volkert-fastned
Copy link

volkert-fastned commented Jan 30, 2023

I see that version 2.14.2 was released yesterday, and includes this improvement in the release notes.

Thank you! 🙏

@cowtowncoder
Copy link
Member

You are welcome @volkert-fastned !

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

3 participants