Re: [jackson-user] JsonMappingException with jackson-databind version 2.8.0 and higher
Could you please file an issue for `jackson-databind`. Looks like a bug. -+ Tatu +- On Thu, Mar 23, 2017 at 5:11 PM, Anuj Kumarwrote: > > I am getting an exception with jackson databind version 2.8.0 and later, > everything works fine with any version below 2.8.0. > > Issue is, if I have a property name with an underscore and the letter after > it is NOT the same as the first letter, then things blow up. > > > For example I have a Person class which contains a Set which has the > name as "person_z" which fails. > > But if I rename it to "person_p" it works. > > > public class Person { > @JsonProperty("name") > private String name; > @JsonProperty("person_z") // renaming this to person_p works > @JsonIgnoreProperties(value = {"person_z"}) // renaming this to person_p > works > private Set personZ; > } > > > public class TestJackson { > > public static void main(String[] args) throws IOException { > > String st =" [ {\n" > + "\"name\": \"admin\",\n" > + "\"person_z\": [" // renaming this to person_p works > + " {" > + "\"name\": \"admin\"" > + " }" > + "]" > + " }]"; > > ObjectMapper mapper = new ObjectMapper(); > mapper.readValue(st, > mapper.getTypeFactory().constructCollectionType(List.class, Person.class)); > } > > } > > > Exception in thread "main" > com.fasterxml.jackson.databind.JsonMappingException: No _valueDeserializer > assigned > at [Source: [ { > "name": "admin", > "person_z": [ {"name": "admin" }] }]; line: 3, > column: 41] (through reference chain: > java.util.ArrayList[0]->com.example.Person["person_z"]->java.util.HashSet[0]->com.example.Person["name"]) > at > com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:261) > at > com.fasterxml.jackson.databind.DeserializationContext.reportMappingException(DeserializationContext.java:1233) > at > com.fasterxml.jackson.databind.deser.impl.FailingDeserializer.deserialize(FailingDeserializer.java:27) > at > com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:490) > at > com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:101) > at > com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276) > at > com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140) > at > com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:277) > at > com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:249) > at > com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:26) > at > com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:490) > at > com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:101) > at > com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276) > at > com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140) > at > com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:277) > at > com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:249) > at > com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:26) > at > com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789) > at > com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2871) > at com.example.TestJackson.main(TestJackson.java:28) > 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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) > > -- > 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
[jackson-user] JsonMappingException with jackson-databind version 2.8.0 and higher
I am getting an exception with jackson databind version 2.8.0 and later, everything works fine with any version below 2.8.0. Issue is, if I have a property name with an underscore and the letter after it is NOT the same as the first letter, then things blow up. For example I have a Person class which contains a Set which has the name as "person_z" which fails. But if I rename it to "person_p" it works. public class Person { @JsonProperty("name") private String name; @JsonProperty("person_z") // renaming this to person_p works @JsonIgnoreProperties(value = {"person_z"}) // renaming this to person_p works private Set personZ; } public class TestJackson { public static void main(String[] args) throws IOException { String st =" [ {\n" + "\"name\": \"admin\",\n" + "\"person_z\": [" // renaming this to person_p works + " {" + "\"name\": \"admin\"" + " }" + "]" + " }]"; ObjectMapper mapper = new ObjectMapper(); mapper.readValue(st, mapper.getTypeFactory().constructCollectionType(List.class, Person.class)); } } Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: No _valueDeserializer assigned at [Source: [ { "name": "admin", "person_z": [ {"name": "admin" }] }]; line: 3, column: 41] (through reference chain: java.util.ArrayList[0]->com.example.Person["person_z"]->java.util.HashSet[0]->com.example.Person["name"]) at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:261) at com.fasterxml.jackson.databind.DeserializationContext.reportMappingException(DeserializationContext.java:1233) at com.fasterxml.jackson.databind.deser.impl.FailingDeserializer.deserialize(FailingDeserializer.java:27) at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:490) at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:101) at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140) at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:277) at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:249) at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:26) at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:490) at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:101) at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:276) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:140) at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:277) at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:249) at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:26) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3789) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2871) at com.example.TestJackson.main(TestJackson.java:28) 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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) -- 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] How to use type name as element name
On Thu, Mar 23, 2017 at 11:34 AM, Zsolt Balanyiwrote: > Hi! > > Unfortunately none of the approaches worked... XmlBeanSerializerModifier has > a bug, and does not use the provided modifier, even if I override the method > you mentioned. > Could you help me where to report the bug? If you can reproduce this without XML backend, it'd make sense to report against `jackson-databind`. If this is truly XML specific, then `jackson-dataformat-xml`. I can help troubleshoot the problem either way, but it would be good to know if it is XML specific or not. > Also where can I find some resources on the architecture of the Jackson > project? I don't think there is much. I have blogged at http://cowtowncoder.com/blog/blog.html (older) https://medium.com/@cowtowncoder (newer) and jackson-docs repo has some links https://github.com/FasterXML/jackson-docs/ but most documentation refers to public API developers are most likely to use. -+ Tatu +- > > BR, Zsolt > > 2017. március 23., csütörtök 6:45:18 UTC+1 időpontban Tatu Saloranta a > következőt írta: >> >> On Wed, Mar 22, 2017 at 10:24 PM, Zsolt Balanyi >> wrote: >> > Hi! >> > >> > Of course my code is related to XML: >> >> Right, I just meant it regarding general data-binding functionality. >> Your code can certainly use its knowledge as necessary. >> >> > >> > ObjectMapper om = new XmlMapper(); >> > om.enable(SerializationFeature.INDENT_OUTPUT); >> > om.registerModule(new JacksonXmlModule() { >> > @Override >> > public void setupModule(SetupContext context) { >> > super.setupModule(context); >> > context.addBeanSerializerModifier(new >> > UIElementSerializerModifier()); >> > } >> > }); >> > >> > public class UIElementSerializerModifier extends >> > XmlBeanSerializerModifier { >> > @Override >> > public JsonSerializer modifySerializer(SerializationConfig >> > config, >> > BeanDescription beanDesc, JsonSerializer serializer) { >> > if (UIElement.class.isAssignableFrom(beanDesc.getBeanClass())) { >> > System.out.println(serializer.getClass().getName()); >> > return new BSerializer((BeanSerializerBase) serializer); >> > } >> > return serializer; >> > } >> > } >> > >> > public class BSerializer extends XmlBeanSerializer { >> > >> > public BSerializer(BeanSerializerBase src) { >> > super(src); >> > } >> > >> > @Override >> > public void serialize(Object bean, JsonGenerator jgen, >> > SerializerProvider provider) throws IOException { >> > // The breakpoint on next line is never hit!!! >> > super.serialize(bean, jgen, provider); >> > } >> > } >> > >> > I create an object that extends UIElement, the appropriate BSerializer >> > is >> > created, but never called. >> > Is this a bug in jackson-dataformat-xml, or I'm doing wrong something? >> >> One possibility is that if the type uses polymorphic handling, method >> called is actually >> >> public void serializeWithType(T value, JsonGenerator g, >> SerializerProvider p, >> TypeSerializer ts); >> >> and you may need to override that as well. >> >> -+ Tatu +- >> >> > >> > BR, Zsolt >> > >> > 2017. március 22., szerda 23:21:03 UTC+1 időpontban Tatu Saloranta a >> > következőt írta: >> >> >> >> On Wed, Mar 22, 2017 at 1:31 AM, Zsolt Balanyi >> >> wrote: >> >> > Hi! >> >> > >> >> > The tag name can be easily renamed, by >> >> > >> >> > if (gen instanceof ToXmlGenerator) { >> >> > ((ToXmlGenerator)gen).setNextName(new >> >> > QName(bean.getClass().getSimpleName())); >> >> > } >> >> > doNormalSerialization(); >> >> >> >> Yes, but that does not mean much when it's `jackson-databind` and its >> >> type handling code which can not call such method >> >> (it is XML specific and not needed for other formats). >> >> >> >> > The only problem is, that I need to serialize all other fields, which >> >> > I >> >> > dont >> >> > know how... That is why I would need to get the method to perform the >> >> > serialization, as the default serializer would. >> >> > Also, the BeanSerializerModifier approach did not work. >> >> > The new serializer is only created, but not called during the >> >> > serialization. >> >> > Maybe it has to something with the fact that I register it for an >> >> > abstract >> >> > class, and the concrete implementors still use their defaults? >> >> >> >> BeanSerializerModifier is a callback, but yes, result would be bound >> >> for whatever type it was called for. >> >> >> >> -+ Tatu +- >> >> >> >> > >> >> > BR Zsolt >> >> > >> >> > >> >> > >> >> > 2017. március 22., szerda 5:38:56 UTC+1 időpontban Tatu Saloranta a >> >> > következőt írta: >> >> >> >> >> >> On Tue, Mar 21, 2017 at 12:16 AM, Zsolt Balanyi >> >> >> >> >> >> wrote: >> >> >> > Hi! >> >> >> > >> >> >> > That was one of
Re: [jackson-user] Ignore property of object in list property of a class
Actually it should already be possible to use `@JsonIgnoreProperties` for properties as is, but I think it only affects property value itself, and not contents of containers. But it seems reasonable to assume that since Lists/arrays/Maps do not have properties of their own (except in non-standard case of being serialized "as POJOs"...), this annotation would refer to values. This is similar to how `@JsonTypeInfo` works. If there isn't yet an issue to support this, could you please file one for `jackson-databind`. I don't know how easy it would be to support this, but conceptually it seems straightforward. -+ Tatu +- On Mon, Mar 20, 2017 at 12:56 AM, Obby Kipchumbawrote: > Let;s say you have the following classes. > > class Client { > List vehicles; > } > > > Class Vehicle { > > > Client owner; > } > > > > What I want to have is a field level annotation as such. > > class Client { > > // something like this > @JsonIgnoreProperties (forEach="owner") > List vehicles; > } > > > Class Vehicle { > > @JsonIgnoreProperties ("vehicles") > Client owner; > } > > > > This is so as to prevent recursion based on the contaxt you are in. I mean > If I have a client object and i'm getting it's vehicles, i don't want the > owner details since I already have the client object but when i have a > vehicle object I will need to know it's owner information but exclude the > list of the vehicles the client has. Isn't this something that someone has > needed at some point in time? > > When you use at class level, like this > > @JsonIgnoreProperties ("owner") > > Class Vehicle { > > Client owner; > } > > > This will ignore the owner all the time regardless of context. Can the > above feature be made possible? > > > > -- > 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.
Re: [jackson-user] WRAP_ROOT_VALUE when serializing
You can enable/disable `SerializationFeature`s using `ObjectWriter` instead of `ObjectMapper`, like so: byte[] bytes = mapper.writer().with(SerializationFeature.WRAP_ROOT_VALUE) .writeValueAsBytes(pojo); I don't know what support Spring Boot offers for doing this. -+ Tatu +- On Mon, Mar 20, 2017 at 3:50 PM, shane leewrote: > Hi all, > > I have asked this question already on github: > https://github.com/FasterXML/jackson-databind/issues/1567 > > What I want is to enable this serilisation feature but only for the pojo i > have defined using @JsonRootName. Not all other pojos that i serialise. How > is that possible? > > Thanks, > Shane. > > > Spring boot version 1.4.0.RELEASE > jackson databind 2.8.1 > > -- > 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] Re: Jackson CSV: Edit header at first row of csv
You have to annote the properties: public class YourClass { @JsonProperty("ID") public int id; @JsonProperty("Fullname") public String name; } Easiest solution would be to use the same names for the properties of your object as in your csv file but I suppose you have your reason for not doing this... -- 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] How to use type name as element name
Hi! Unfortunately none of the approaches worked... XmlBeanSerializerModifier has a bug, and does not use the provided modifier, even if I override the method you mentioned. Could you help me where to report the bug? Also where can I find some resources on the architecture of the Jackson project? BR, Zsolt 2017. március 23., csütörtök 6:45:18 UTC+1 időpontban Tatu Saloranta a következőt írta: > > On Wed, Mar 22, 2017 at 10:24 PM, Zsolt Balanyi> wrote: > > Hi! > > > > Of course my code is related to XML: > > Right, I just meant it regarding general data-binding functionality. > Your code can certainly use its knowledge as necessary. > > > > > ObjectMapper om = new XmlMapper(); > > om.enable(SerializationFeature.INDENT_OUTPUT); > > om.registerModule(new JacksonXmlModule() { > > @Override > > public void setupModule(SetupContext context) { > > super.setupModule(context); > > context.addBeanSerializerModifier(new > > UIElementSerializerModifier()); > > } > > }); > > > > public class UIElementSerializerModifier extends > XmlBeanSerializerModifier { > > @Override > > public JsonSerializer modifySerializer(SerializationConfig > config, > > BeanDescription beanDesc, JsonSerializer serializer) { > > if (UIElement.class.isAssignableFrom(beanDesc.getBeanClass())) { > > System.out.println(serializer.getClass().getName()); > > return new BSerializer((BeanSerializerBase) serializer); > > } > > return serializer; > > } > > } > > > > public class BSerializer extends XmlBeanSerializer { > > > > public BSerializer(BeanSerializerBase src) { > > super(src); > > } > > > > @Override > > public void serialize(Object bean, JsonGenerator jgen, > > SerializerProvider provider) throws IOException { > > // The breakpoint on next line is never hit!!! > > super.serialize(bean, jgen, provider); > > } > > } > > > > I create an object that extends UIElement, the appropriate BSerializer > is > > created, but never called. > > Is this a bug in jackson-dataformat-xml, or I'm doing wrong something? > > One possibility is that if the type uses polymorphic handling, method > called is actually > > public void serializeWithType(T value, JsonGenerator g, > SerializerProvider p, > TypeSerializer ts); > > and you may need to override that as well. > > -+ Tatu +- > > > > > BR, Zsolt > > > > 2017. március 22., szerda 23:21:03 UTC+1 időpontban Tatu Saloranta a > > következőt írta: > >> > >> On Wed, Mar 22, 2017 at 1:31 AM, Zsolt Balanyi > >> wrote: > >> > Hi! > >> > > >> > The tag name can be easily renamed, by > >> > > >> > if (gen instanceof ToXmlGenerator) { > >> > ((ToXmlGenerator)gen).setNextName(new > >> > QName(bean.getClass().getSimpleName())); > >> > } > >> > doNormalSerialization(); > >> > >> Yes, but that does not mean much when it's `jackson-databind` and its > >> type handling code which can not call such method > >> (it is XML specific and not needed for other formats). > >> > >> > The only problem is, that I need to serialize all other fields, which > I > >> > dont > >> > know how... That is why I would need to get the method to perform the > >> > serialization, as the default serializer would. > >> > Also, the BeanSerializerModifier approach did not work. > >> > The new serializer is only created, but not called during the > >> > serialization. > >> > Maybe it has to something with the fact that I register it for an > >> > abstract > >> > class, and the concrete implementors still use their defaults? > >> > >> BeanSerializerModifier is a callback, but yes, result would be bound > >> for whatever type it was called for. > >> > >> -+ Tatu +- > >> > >> > > >> > BR Zsolt > >> > > >> > > >> > > >> > 2017. március 22., szerda 5:38:56 UTC+1 időpontban Tatu Saloranta a > >> > következőt írta: > >> >> > >> >> On Tue, Mar 21, 2017 at 12:16 AM, Zsolt Balanyi > > >> >> wrote: > >> >> > Hi! > >> >> > > >> >> > That was one of my first attempts :) > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > > >> >> > The question is how could I ommit the uiElement nodes? > >> >> > >> >> itself matches property `uiElement` so that can not be > >> >> removed. > >> >> Or, if expectation was that property name would be replaced by type > id > >> >> that is not something Jackson supports or will be able to support -- > >> >> it may make sense from XML viewpoint, but would not work with JSON > or > >> >> any other supported dataformat. XML is bit of an outlier as