Open rvervaek opened 5 years ago
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");
Hi,
I'm having issues using the 'defaultImpl' attribute of JsonTypeInfo annotation. This is the situation:
` public class Example {
}
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "@class", defaultImpl = Example.class) public class ExampleExtended extends Example {
}
public class JsonConfig extends AbstractConfiguration {
} `
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:
But when receiving the Example object, a JsonDeserializationException is thrown with the following message:
I tested this also with 'JsonTypeInfo.Id.NAME' but this gives the same error:
I'm using the following versions: