-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Field in base class is not recognized, when using @JsonType.defaultImpl
#1083
Comments
That does seem wrong. Would it be possible to have a minimalistic test case? I assume much of this could be removed while still reproduce the exception. |
Here you go: import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ModelTest2 {
public static void main(String[] args) throws IOException {
final ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
final String json = "{\n"
+ " schemas: [\n"
+ " {\n"
+ " name: 'FoodMart'\n"
+ " }\n"
+ " ]\n"
+ "}";
mapper.readValue(json, JsonRoot.class);
}
public static class JsonRoot {
public final List<JsonSchema> schemas = new ArrayList<>();
}
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type",
defaultImpl = JsonMapSchema.class)
@JsonSubTypes({
@JsonSubTypes.Type(value = JsonMapSchema.class, name = "map"),
@JsonSubTypes.Type(value = JsonJdbcSchema.class, name = "jdbc") })
public static abstract class JsonSchema {
public String name;
}
public static class JsonMapSchema extends JsonSchema {
}
public static class JsonJdbcSchema extends JsonSchema {
}
} |
Thanks! |
Yes, I can reproduce this. Interesting enough, this only occurs when |
@JsonType.defaultImpl
Ok... somewhat ironic; this was due to one thing I suspected could cause problems. And so it did. I was able to patch this to pass for tested case, and some others; but I'll file another issue for a bigger fix that may need to wait until 2.8. But patch should work for common cases until then. |
Glad I was able to help. Having just upgraded from 2.1.1, I'm perfectly happy with 2.6.3 for now and looking forward to trying YAML support. By the way, thank you for producing an excellent open source project. Jackson is a pleasure to use. |
@julianhyde Thank you -- glad you have enjoyed using it. And also for the bug report. |
# By Tatu Saloranta (113) and others # Via Tatu Saloranta * 'master' of https://github.com/FasterXML/jackson-databind: (124 commits) Minor addition related to FasterXML#1087: resolve context type, assuming type bindings from that are expected to work. Add unit test for FasterXML#999 minor warnings cleanup Add Javadoc badge with automatic version detection Fix FasterXML#1083 Add failing test for FasterXML#1083 add a unit test to verify that Object Id works via AtomicReference too Minor javadoc improvement wrt FasterXML#1076, making `SimpleType.construct(Class)` deprecated (was not yet, for some reason, should have been) Fix FasterXML#1078 Fix FasterXML#1079 [maven-release-plugin] prepare for next development iteration [maven-release-plugin] prepare release jackson-databind-2.7.0 prepare for 2.7.0 final Fix FasterXML#1073 Try to reproduce FasterXML#1074 javadoc trimming Try to reproduce FasterXML#825 again, still passes. minor improvement to ensure base64 encoding uses configured setting Undo part of change done for StringDeserializer; caused issues with XML handling further minor cleanups to cleanup ...
When deserializing JSON to Java POJOS, a field inherited from a base class is not recognized. Here is the stack:
My
JsonMapSchema
class has a base classJsonSchema
and it has a public fieldname
. See https://github.com/apache/calcite/blob/master/core/src/test/java/org/apache/calcite/test/ModelTest.java.I have an application that worked in 2.6.3, fails in 2.7.0, so I suspect this is a regression.
The text was updated successfully, but these errors were encountered: