[jackson-user] serializing POJOs
Hello, has anyone had experience with http://wiki.fasterxml.com/JacksonDataBinding Can Jackson or another product that you produce, help me with using a bean to data bind as JSON? JSF managed bean accessing MySQL remote database - how to create JSON array to feed http://stackoverflow.com/questions/41142802/jsf-managed-bean-accessing-mysql-remote-database-how-to-create-json-array-to-f Any suggestions greatly appreciated. Jon -- 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] Type info is not serialized when a @JsonTypeInfo element is a part of a collection or map
The reason for (4) is the good old Java Type Erasure. What you writing out is essentially `Map`, as far as available type information tells -- there is nothing that could tell otherwise. So as general rule: - Do not serialize generic values as root value, if possible. o but if you do, you MUST provide type information separately o or, sub-class generic type to make it non-generic Like so: // instead of using reflection, construct as `TypeReference` final TypeReference fooType = new TypeReference>() { }; // (or using `TypeFactory.constructMapType(...)`) // important: since root value is generic, MUST provide extra info to avoid // it being seen as `Map` String json = m.writerFor(fooType) .writeValueAsString(o); // after which read succeeds: System.out.println ("5) " + m.readValue(json, fooType)); Or, with a work-around involving sub-classing to get non-generic type: static class FooMap extends HashMap { } and you do NOT need to specify type for serialization because type information is now available via super-type declaration (so it's in class definition; runtime type is still type-erased but that does not matter). I hope this helps, -+ Tatu +- On Tue, Dec 13, 2016 at 11:53 AM, Lev Kuznetsov wrote: > Try the code I pasted without the getter, it won't serialize type > information if the object is a value in a map I'm trying to serialize (and > same as part of a collection). The output for the code I pasted above is > > 1) {"@class":"foo.Test$Bar","lol":"lol"} > > 2) .Bar > > 3) {f=.Bar} > > 4) {"f":{"lol":"lol"}} > > Exception in thread "main" > com.fasterxml.jackson.databind.JsonMappingException: Unexpected token > (END_OBJECT), expected FIELD_NAME: missing property '@class' that is to > contain type id (for class foo.Test$Foo) > > > Where the first line is serialization of the object itself, the fourth line > is serialization of a map mapping the string "f" to the same object, notice > how "@class" property is missing, followed by exception where it cannot > deserialize this json back into a map. > > -- > 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] Object Mapper from managed bean POJO to JSON
Hello, I have not seen HOW any data is retrieved from the MODEL -- IF there is no reference to the managed bean that connects the remote MySQL data source. How can there be an Object Mapping without any connection to the data? what is the proper method of sharing code in this groups policy? -- 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] Re: serializing POJOs
I have posted a new TOPIC that expands on this, shall close this topic -- as it received NO VIEWS. and continue to hope someone may have a brief moment to explain something relatively simple ONCE KNOWN, how to code a STANDARD Object Mapping from POJO (with managed bean remote MySQL data connectivity- referenced) to JSON string. On Wednesday, December 14, 2016 at 4:48:33 PM UTC-8, Literate Aspects wrote: > > Hello, has anyone had experience with > > > http://wiki.fasterxml.com/JacksonDataBinding > > Can Jackson or another product that you produce, help me with using a bean > to data bind as JSON? > > JSF managed bean accessing MySQL remote database - how to create JSON > array to feed > > > http://stackoverflow.com/questions/41142802/jsf-managed-bean-accessing-mysql-remote-database-how-to-create-json-array-to-f > > Any suggestions greatly appreciated. > > Jon > -- 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] Re: Object Mapper from managed bean POJO to JSON
On Wednesday, December 14, 2016 at 11:44:46 PM UTC-8, Literate Aspects wrote: > > Hello, I have not seen HOW any data is retrieved from the MODEL -- IF > there is no reference to the managed bean that connects the remote MySQL > data source. > > How can there be an Object Mapping without any connection to the data? > > what is the proper method of sharing code in this groups policy? > > > NOTES FROM post that receive NO VIEWS: I have posted a new TOPIC that expands on this, shall close this topic -- as it received NO VIEWS. and continue to hope someone may have a brief moment to explain something relatively simple ONCE KNOWN, how to code a STANDARD Object Mapping from POJO (with managed bean remote MySQL data connectivity- referenced) to JSON string. On Wednesday, December 14, 2016 at 4:48:33 PM UTC-8, Literate Aspects wrote: > > Hello, has anyone had experience with > > > http://wiki.fasterxml.com/JacksonDataBinding > > Can Jackson or another product that you produce, help me with using a bean > to data bind as JSON? > > JSF managed bean accessing MySQL remote database - how to create JSON > array to feed > > > http://stackoverflow.com/questions/41142802/jsf-managed-bean-accessing-mysql-remote-database-how-to-create-json-array-to-f > > Any suggestions greatly appreciated. > > Jon -- 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] Re: Object Mapper from managed bean POJO to JSON
On Wednesday, December 14, 2016 at 11:44:46 PM UTC-8, Literate Aspects wrote: > > Hello, I have not seen HOW any data is retrieved from the MODEL -- IF > there is no reference to the managed bean that connects the remote MySQL > data source. > > How can there be an Object Mapping without any connection to the data? > > what is the proper method of sharing code in this groups policy? > > > > > -- 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.