Skip to content

JsonTypeInfo defaultImpl attribute not working #154

Open
@rvervaek

Description

@rvervaek

Hi,

I'm having issues using the 'defaultImpl' attribute of JsonTypeInfo annotation. This is the situation:

`
public class Example {

private String name;

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

}

@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "@Class", defaultImpl = Example.class)
public class ExampleExtended extends Example {

private boolean isImport;

public boolean isImport() {
    return isImport;
}

public void setImport(boolean anImport) {
    isImport = anImport;
}

}

public class JsonConfig extends AbstractConfiguration {

@Override
protected void configure() {
    addMixInAnnotations(Example.class, ExampleExtended.class);
}

}
`

My client application makes HTTP calls to 2 different servers. One server returns ExampleExtended instances and thus adds the '@Class' property containing the type information. The second server returns Example instances and thus does not add the '@Class' property containing the type information. However I specified the attribute 'defaultImpl' that will use that Example class when the type information is not present as explained in the javadoc:

Optional property that can be used to specify default implementation class to use for deserialization if type identifier is either not present, or can not be mapped to a registered type (which can occur for ids,
but not when specifying explicit class to use).

But when receiving the Example object, a JsonDeserializationException is thrown with the following message:

Cannot find the property @Class containing the type information

I tested this also with 'JsonTypeInfo.Id.NAME' but this gives the same error:

Cannot find the property @type containing the type information

I'm using the following versions:

  • gwt-jackson: 0.15.4
  • jackson-annotations: 2.9.0
  • gwt: 2.8.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions