I'm trying to use Jackson to serialize and deserialize objects (marshall/unmarshall) from and to JSON. Some of these objects have Java 8 LocalDate and ZonedDateTime. I've read here that the best option is to use jackson-datatype-jsr310
serialize/deserialize java 8 java.time with Jackson JSON mapper
However, when I try to use this:
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
I get this error:
java.lang.IllegalAccessError: tried to access method com.fasterxml.jackson.databind.ser.std.StdSerializer.<init>(Ljava/lang/Class;)V from class com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
Any clue? I'm using Jackson 2.6.0, jackson-datatype-jsr310 2.6.0 and am deploying to Tomcat 8.
Thanks and best regards
In the end, the problem was I had a different version of Jackson, due to a dependency with Jongo. jackson-datatype-jsr310 2.6.0 needs Jackson 2.6.0 and Jackson 2.4.1 was being deployed.
Related
I'm upgrading the version of jackson-databind to 2.14.2 version .But I noticed that ObjectMapper's configure method for mapper feature is deprecated.
Deprecated
Since 2.13 use JsonMapper.builder().configure(...)
Is it possible to edit configure of existing object mapper for mapper feature using that method? if possible, how to do that?
I have searching for the solution, but i just find the solution for configure new object mapper not for existing object mapper
I am writing a java-library that will be included included as a dependency in other projects. I want some of the library's classes to de/serializable with Jackson's ObjectMapper. Out of habit, I have used annotations to tell Jackson how to de/serialize my classes.
Will the annotations' functionality get exported by the library (like api)?
Will a dependent application be able to use the an ObjectMapper created by the default constructor? Is any further configuration necessary?
Can I put the annotations into a custom Jackson Module for dependent applications to register with their ObjectMapper?
I have been very surprised to find a dearth of documentation for this use case.
i am developing a restful service with tomcat 7 and jdk 1.6. for json handling i am using jackson 2.4.2 and it works fine except when i try and deserialise an object (that it has no trouble serialising).
the error is:
java.lang.ClassNotFoundException: org.codehaus.jackson.JsonFactory
which is the place where jackson 1.x kept that particular class. my jackson 2.4.2 has it at
com.fasterxml.jackson.core.JsonFactory
i have no idea as to why it is trying to link the old class. i never used jackson 1.x.
what i use:
asm-3.3.1
commons-io-2.4
jackson-core-2.4.2
jackson-databind-2.4.2
jersey-bundle-1.18
mysql-connector-java-5.1.27
and
com.fasterxml.jackson.annotation
which i have taken from github. what library could be trying to import the old jackson module? any help would be much appreciated.
The issue certainly comes from trying to use Jackson 1.x ObjectMapper and missing underlying JsonFactory for 1.x. Since these come from difference jars (jackson-mapper-asl vs jackson-core-asl), it is likely that somehow one is missing.
Now, since you are not directly using Jackson 1.x, question is who is: perhaps jersey is relying on 1.x?
So there are two related questions: (a) if Jackson 1.x is needed, to bring in core jar as well, or (b) how to remove use of Jackson 1.x altogether.
Note that technically it is quite possible to use both 1.x and 2.x versions of Jackson, since 2.x was specifically designed to be able to co-exist. This to make upgrades easier, and allow gradual (component-by-component) upgrading.
This is the opposite of what most Spring users are clamoring to do, but I was wondering if its possible to specify that Jackson 1.9.7 be used by Spring (3.1.2) and NOT Jackson 2+.
The project I'm working on relies on other projects that use Jackson 2, so it get pulls in as a transitive dependency. From there Spring picks it up to handle JSON serialization. This in turn borks my application because of custom annotations I've created that require the Jackson version be 1.9.7.
Not sure if this helps, but note that you can also add both Jackson 1 and Jackson 2 annotations in value classes. I have done this at work, to help transition from Jackson 1.9 to Jackson 2.x. And in fact different parts of code use different version: unit test helper methods were migrated first, and later on production code, section by section.
As with library version, use of two sets of annotations is not optimal, but doing so may help reduce risk of version upgrade.
Finally, it is also possible to use an AnnotationIntrospector that can use both sets of annotations (I don't have a link at hand, but I know a Jackson user published version he created); usually Jackson 2 JacksonAnnotationIntrospector that also recognizes Jackson 1 annotations. This avoids duplication of annotations and makes it possible to upgrade code first, then convert annotations.
Have a bunch of classes which I need to do serialize and deserialize from/to JSON/XML at the same time. Which library you recommend to this task?
I like Jackson for JSON, and XStream for XML. We use them both in a product and they're pretty rugged. Jackson is very fast.
Update: #radai suggests the Simple XML library, which looks pretty interesting.
For xml we use simple (simple.sourceforge.net)
You can do both with Jackson: core package handles JSON, and xml-databinding extension module can do XML.
There are other modules that support BSON and CSV, as well; Jackson is becoming a general-purpose data-binding tool.
Here's a good resource for json
Here's a good resource for processing xml