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 defaultImpl attribute not working #154

Open
rvervaek opened this issue Feb 28, 2019 · 1 comment
Open

JsonTypeInfo defaultImpl attribute not working #154

rvervaek opened this issue Feb 28, 2019 · 1 comment

Comments

@rvervaek
Copy link

rvervaek commented Feb 28, 2019

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
@jorissynaeve
Copy link

jorissynaeve commented Mar 23, 2021

I see I have the same problem.

I have a class DataDto
public class DataDto { List<A> data; // + getters and setters }

The class A (default class)
public class A { String id; // + getters and setters }

The class B (extends A)
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "@class", defaultImpl = A.class) public class B extends A { String name; // + getters and setters }

From 1 server, I get an A json. It's deserialized as A
{ data: [ { id = 5 }, {id = 6} ] }

From another server, I get an B json. It's deserialized as A but should be as B.
{ data: [ { @class: "B", id = 5, name = "test1" }, { @class: "B", id = 6, name = "test2"} ] }

Any clues?

I tried to add all possible combinations in whitelist without luck. Example
whitelist("x.x.x.B");

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