Re: [jackson-user] Custom Deserializer

2018-04-09 Thread sean
That worked.  Thanks for the suggestion Tatu.

On Monday, April 9, 2018 at 6:47:15 PM UTC-4, Tatu Saloranta wrote:
>
> Do you think `@JsonAnySetter` would work here, attached to Map? It 
> would get all values that do not map to existing regular properties? 
> It wouldn't do anything for underscores but would allow easy collection. 
>
> Or, if you want to strip underscore, you could specify method instead 
>
>   @JsonAnySetter 
>   void addProperty(String name, String value) { 
>   // modify name, add to Map 
>} 
>
>
> -+ Tatu +- 
>
>
> On Mon, Apr 9, 2018 at 2:17 PM,   wrote: 
> > Hello, 
> > 
> > I'm trying to figure out the best way to implement a deserializer for 
> the 
> > following setup: 
> > 
> > class Model { 
> >   private String prop1; 
> >   private String prop2; 
> >   Map userDefined; 
> > } 
> > 
> > json: 
> > 
> > { 
> >   "prop1": "prop one", 
> >   "prop2": "prop two", 
> >   "_prop3": "prop three", 
> >   "_prop4": "prop four" 
> > } 
> > 
> > The fields prefixed with an underscore represent dynamic fields that 
> can't 
> > be known in advance.  My goal is to use the default deserializer and 
> then 
> > map the props prefixed with underscores to entries in the Map.  Can 
> someone 
> > point me in the right direction on a solution?  I'm hoping to avoid 
> doing a 
> > manual deserialization and ride on the default serializer if possible. 
> > 
> > Thanks in advance, 
> > Sean 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "jackson-user" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to jackson-user...@googlegroups.com . 
> > To post to this group, send email to jackso...@googlegroups.com 
> . 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [jackson-user] Custom Deserializer

2018-04-09 Thread Tatu Saloranta
Do you think `@JsonAnySetter` would work here, attached to Map? It
would get all values that do not map to existing regular properties?
It wouldn't do anything for underscores but would allow easy collection.

Or, if you want to strip underscore, you could specify method instead

  @JsonAnySetter
  void addProperty(String name, String value) {
  // modify name, add to Map
   }


-+ Tatu +-


On Mon, Apr 9, 2018 at 2:17 PM,   wrote:
> Hello,
>
> I'm trying to figure out the best way to implement a deserializer for the
> following setup:
>
> class Model {
>   private String prop1;
>   private String prop2;
>   Map userDefined;
> }
>
> json:
>
> {
>   "prop1": "prop one",
>   "prop2": "prop two",
>   "_prop3": "prop three",
>   "_prop4": "prop four"
> }
>
> The fields prefixed with an underscore represent dynamic fields that can't
> be known in advance.  My goal is to use the default deserializer and then
> map the props prefixed with underscores to entries in the Map.  Can someone
> point me in the right direction on a solution?  I'm hoping to avoid doing a
> manual deserialization and ride on the default serializer if possible.
>
> Thanks in advance,
> Sean
>
> --
> You received this message because you are subscribed to the Google Groups
> "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jackson-user+unsubscr...@googlegroups.com.
> To post to this group, send email to jackson-user@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[jackson-user] Custom Deserializer

2018-04-09 Thread sean
Hello,

I'm trying to figure out the best way to implement a deserializer for the 
following setup:

class Model {
  private String prop1;
  private String prop2;
  Map userDefined;
}

json:

{
  "prop1": "prop one",
  "prop2": "prop two",
  "_prop3": "prop three",
  "_prop4": "prop four"
}

The fields prefixed with an underscore represent dynamic fields that can't 
be known in advance.  My goal is to use the default deserializer and then 
map the props prefixed with underscores to entries in the Map.  Can someone 
point me in the right direction on a solution?  I'm hoping to avoid doing a 
manual deserialization and ride on the default serializer if possible.

Thanks in advance,
Sean

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [jackson-user] Jackson 2.9.5 case sensitive problem

2018-04-09 Thread Marte Marte
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 
>