Re: [jackson-user] Jackson 2.9.5 case sensitive problem
Thanks for suggestion, point 2) solve problem for me! I've made with my test case an example repo here: https://github.com/albertotn/Jackson-dataformat-xml-test Il giorno sabato 7 aprile 2018 00:09:01 UTC+2, Tatu Saloranta ha scritto: > > Ok, couple of notes: > > 1. Jackson does not know or care about XSD: the only thing that > matters is generated Java class(es) > 2. If using JAXB annotations, make sure to register > JAXBAnnotationIntrospector: by default Jackson only uses its own > annotations; > but `AnnotationIntrospector` allows supporting non-native > annotation sets too, such as JAXB ones. > 3. A good way to troubleshoot structural mismatch is to take an > object, then serialize it (write) as xml, see if that match, and if > not, how > 4. A common structural mismatch is for List/Collection values, > regarding whether there is a wrapper element for property (in addition >to elements per value) -- by default JAXB DOES NOT use them, and by > default Jackson DOES use wrappers. You may want to >disable use of wrappers either on per-property basis (there's a > Jackson annotation for that), or, as default for all properties. > > I hope this helps, > > -+ Tatu +- > > > > > On Thu, Apr 5, 2018 at 8:18 AM, Marte Marte> wrote: > > Hello everyone, > > I hope to find some help on this "strange" issue or a different look > to > > this problem. > > > > Let's start from a simple xsd, like this one: > > > > > >> http://flussi.mds.it/flsassdom_1; > >> xmlns:xs="http://www.w3.org/2001/XMLSchema; > >> targetNamespace="http://flussi.mds.it/flsassdom_1; > >> elementFormDefault="qualified" > >> attributeFormDefault="unqualified"> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > > > > From this xsd from Eclipse using "default" jaxb implementation I have > > generated corresponding classes. > > Now, if I start from following example xml: > > > > > > http://flussi.mds.it/flsassdom_1;> > > > > 123 > > > > > > > > > > And try to use it with Jackson: > > > > > >> public class MapperTest { > >> > >> @Test > >> public void simpleMapperTest() throws JsonParseException, > >> JsonMappingException, IOException { > >> XmlMapper mapper = new XmlMapper(); > >> File f = new > >> File(this.getClass().getResource("example.xml").getFile()); > >> > >> FlsAssDom1 read = mapper.readValue(f, FlsAssDom1.class); > >> > >> assertTrue(read != null); > >> } > >> > >> } > > > > > > > > And what I receive is the following exception: > > > > > >> com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: > >> Unrecognized field "Residenza" (class it.test.model.FlsAssDom1), not > marked > >> as ignorable (one known property: "residenza"]) > >> at [Source: (File); line: 4, column: 9] (through reference chain: > >> it.test.model.FlsAssDom1["Residenza"]) > >> at > >> > com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61) > > > >> at > >> > com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:822) > > > >> at > >> > com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1152) > > > >> at > >> > com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1582) > > > >> at > >> > com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1560) > > > >> at > >> > com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:294) > > > >> at > >> > com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151) > > > >> at > >> > com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4001) > > > >> at > >> > com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2890) > > >> at MapperTest.simpleMapperTest(MapperTest.java:21) > >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > >> at > >> > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > > >> at > >> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > > > >> at java.lang.reflect.Method.invoke(Method.java:498) > >> at > >> > org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) > > > >> at > >> > org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) > > > >> at >
Re: [jackson-user] Jackson 2.9.5 case sensitive problem
Ok, couple of notes: 1. Jackson does not know or care about XSD: the only thing that matters is generated Java class(es) 2. If using JAXB annotations, make sure to register JAXBAnnotationIntrospector: by default Jackson only uses its own annotations; but `AnnotationIntrospector` allows supporting non-native annotation sets too, such as JAXB ones. 3. A good way to troubleshoot structural mismatch is to take an object, then serialize it (write) as xml, see if that match, and if not, how 4. A common structural mismatch is for List/Collection values, regarding whether there is a wrapper element for property (in addition to elements per value) -- by default JAXB DOES NOT use them, and by default Jackson DOES use wrappers. You may want to disable use of wrappers either on per-property basis (there's a Jackson annotation for that), or, as default for all properties. I hope this helps, -+ Tatu +- On Thu, Apr 5, 2018 at 8:18 AM, Marte Martewrote: > Hello everyone, > I hope to find some help on this "strange" issue or a different look to > this problem. > > Let's start from a simple xsd, like this one: > > >> http://flussi.mds.it/flsassdom_1; >> xmlns:xs="http://www.w3.org/2001/XMLSchema; >> targetNamespace="http://flussi.mds.it/flsassdom_1; >> elementFormDefault="qualified" >> attributeFormDefault="unqualified"> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> > > From this xsd from Eclipse using "default" jaxb implementation I have > generated corresponding classes. > Now, if I start from following example xml: > > > http://flussi.mds.it/flsassdom_1;> > > 123 > > > > > And try to use it with Jackson: > > >> public class MapperTest { >> >> @Test >> public void simpleMapperTest() throws JsonParseException, >> JsonMappingException, IOException { >> XmlMapper mapper = new XmlMapper(); >> File f = new >> File(this.getClass().getResource("example.xml").getFile()); >> >> FlsAssDom1 read = mapper.readValue(f, FlsAssDom1.class); >> >> assertTrue(read != null); >> } >> >> } > > > > And what I receive is the following exception: > > >> com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: >> Unrecognized field "Residenza" (class it.test.model.FlsAssDom1), not marked >> as ignorable (one known property: "residenza"]) >> at [Source: (File); line: 4, column: 9] (through reference chain: >> it.test.model.FlsAssDom1["Residenza"]) >> at >> com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61) >> at >> com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:822) >> at >> com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1152) >> at >> com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1582) >> at >> com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1560) >> at >> com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:294) >> at >> com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151) >> at >> com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4001) >> at >> com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2890) >> at MapperTest.simpleMapperTest(MapperTest.java:21) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) >> at >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) >> at java.lang.reflect.Method.invoke(Method.java:498) >> at >> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) >> at >> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) >> at >> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) >> at >> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) >> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) >> at >> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) >> at >> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) >> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) >> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) >> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) >> at