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

@JsonSerialize(as=superType) behavior disallowed in 2.7.4 #1231

Closed
markwoon opened this issue May 13, 2016 · 3 comments
Closed

@JsonSerialize(as=superType) behavior disallowed in 2.7.4 #1231

markwoon opened this issue May 13, 2016 · 3 comments
Milestone

Comments

@markwoon
Copy link
Contributor

#1178 fixed the problem with collections, but I'm seeing a problem with individual objects.

I'm getting:

com.fasterxml.jackson.databind.JsonMappingException: Failed to widen type [simple type, class org.pharmgkb.model.AccessionIdentifier] with annotation (value org.pharmgkb.model.BaseAccessionIdentifier), from 'getReference': Class org.pharmgkb.model.BaseAccessionIdentifier not a super-type of [simple type, class org.pharmgkb.model.AccessionIdentifier]

    at com.fasterxml.jackson.databind.AnnotationIntrospector.refineSerializationType(AnnotationIntrospector.java:821)
    at com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair.refineSerializationType(AnnotationIntrospectorPair.java:488)
    at com.fasterxml.jackson.databind.ser.PropertyBuilder.findSerializationType(PropertyBuilder.java:194)
    at com.fasterxml.jackson.databind.ser.PropertyBuilder.buildWriter(PropertyBuilder.java:73)
    at com.fasterxml.jackson.databind.ser.BeanSerializerFactory._constructWriter(BeanSerializerFactory.java:805)
    at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.findBeanProperties(BeanSerializerFactory.java:608)
    at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.constructBeanSerializer(BeanSerializerFactory.java:388)
    at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.findBeanSerializer(BeanSerializerFactory.java:271)
    at com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:223)
    at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:157)
    at com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1215)
    at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1167)
    at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:490)
    at com.fasterxml.jackson.databind.SerializerProvider.findTypedValueSerializer(SerializerProvider.java:688)
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:107)
    at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1428)
    at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:1129)
    at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:1001)
    at org.pharmgkb.jackson.JacksonTest.testModelObjects(JacksonTest.java:48)

On something like:

public class Foo {
  @JsonSerialize(as = BaseAccessionIdentifier.class)
  @JsonDeserialize(as = BaseAccessionIdentifier.class)
  public AccessionIdentifier getReference() {
  }
}
public interface AccessionIdentifier {
}
public class BaseAccessionIdentifier implements AccessionIdentifier {
}
@cowtowncoder
Copy link
Member

Thank you for reporting this. Looks like this could be related to delegation via annotation introspector pair.

cowtowncoder added a commit that referenced this issue May 19, 2016
@cowtowncoder
Copy link
Member

I can reproduce this easily, nothing to do with introspector pair delegation; also fails with master (2.8.0-SNAPSHOT).

@cowtowncoder cowtowncoder added this to the 2.7.5 milestone May 19, 2016
@cowtowncoder
Copy link
Member

Ok yes, my bad. Just had not extended this to as or keyAs cases, just contentAs.

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