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

JsonType.As.EXISTING_PROPERTY cannot handle multiple types with same class #716

Closed
natnan opened this issue Mar 3, 2015 · 4 comments
Closed

Comments

@natnan
Copy link

natnan commented Mar 3, 2015

This doesn't seem to be a problem when using JsonType.As.PROPERTY, so I didn't consider it as an illegal thing to do.

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", include = JsonTypeInfo.As.EXISTING_PROPERTY)
@JsonSubTypes({
    @JsonSubTypes.Type(value = SubClass1.class, name = "1"),
    @JsonSubTypes.Type(value = SubClass1.class, name = "1,5"),
    @JsonSubTypes.Type(value = SubClass2.class, name = "2"),
    @JsonSubTypes.Type(value = SubClass2.class, name = "2.25"),
    @JsonSubTypes.Type(value = SubClass2.class, name = "2.5"),
    @JsonSubTypes.Type(value = SubClass2.class, name = "2.75")
})

And this is the exception message I get:

Could not resolve type id 'Create' into a subtype of [simple type, class com.test.MySuperTestPojo]: known type ids = [MySuperTestPojo, 1, 2]

I'll try to write a unit test when I have time later

P.S.: (If I use As.Property, it ignores JsonPropertyOrder, and I think it serializes the properties in a somewhat random order. Another issue?)

@natnan
Copy link
Author

natnan commented Mar 3, 2015

Actually, I'm having the same issue with As.PROPERTY now as well. Maybe it's something else.. I'll update this when i know more.

@cowtowncoder
Copy link
Member

I think this is #312, which will be fixed in 2.6.0. So you may want to try 2.6.0-SNAPSHOT to see if that might help.

@cowtowncoder
Copy link
Member

As to ordering: it should retain ordering (minus actual property used which will be serialized as the first thing). Although if you have existing property you want to bind to, and you want to specify its ordering, As.EXISTING_PROPERTY should retain ordering of even that one property.

If ordering is otherwise messed up, that would be a bug (type id and object id are exceptions to the rule).

@natnan
Copy link
Author

natnan commented Mar 3, 2015

Yes, looks like #312 is the issue which I didn't come across because I thought it was a problem with As.EXISTING_PROPERTY and that's what I've searched before posting. I've tried with 2.6.0-SNAPSHOT and it seems to be working fine.

As for the ordering, yes that was my expectation which wasn't met. I've tried to reproduce it with unit tests on 2.6.0 but didn't manage to. Maybe I was doing something wrong and misread things; or some chained actions were causing it as lots of object mapping occurs before it happens in the application tests.

Thank you!

@natnan natnan closed this as completed Mar 3, 2015
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