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.
Related
I'm writing a class to provide some logging output in JSON format.
One issue is that the various Java projects I work on already use JSON and have dependencies on 3rd party libraries like gson or Jackson.
The work the class needs to perform is quite small and I figured it should be easy to avoid creating a new dependency on any particular JSON library, analagous to SLF4j which picks up whatever logging framework is already present.
My plan is that the class would pick up a JSON engine and use it, or throw a "missing JSON library" exception at start-up.
Does this already exists? I can't find anything on the net.
Is the Java JDK service provider java.util.ServiceLoader suitable?
It seemed easy enough to implement when I used it to plug in a java.nio.file.spi.FileTypeDetector for mime type detection with Apache Tika (best explained on this useful blog post.
You could try Class.forName(), passing the full name of the core class for Gson, Jackson, or whatever other JSON library is in use. If the class is not on the classpath, you will get a ClassNotFound exception. If you did this test only once, the cost would be reasonable.
I'm getting crazy regarding JAX-RS 2 usage (Jersey 2.17). I migrated from JAX-RS 1.0 and some texts posted here are explaining to use response.readEntity(Class.class). But this method is missing in Jersey 2.17. Is its documentation outdated? How could I extract an entity from Response?
I found a problem in my pom.xml . It was a outdated glassfish-embedded-web with a conflict in Jersey. I removed it and now it's working fine.
I am using jersey-server, jersey-client, jersey-container-servlet-core, all 3 of version 2.23.1. Please make sure you have imported javax.ws.rs-api version 2.0.1 or later. I had not imported it in my build.gradle. After importing, I was able to see readEntity method for my Response class.
We have started using the new 1.0 version of JavaMoney API with the reference implementation. Since we have specific Exchangerates that should be used, we need to implement our own ExchangeRateProvider. We have created a class MyRateProvider that extends org.javamoney.moneta.spi.AbstractRateProvider and added MyRateProvider-name to the file META-INF/services/javax.money.convert.ExchangeRateProvider. It works, but all the other providers in org.javamoney.moneta are also loaded even if we are not going to use them. Is there a way to avoid that?
We have an issue today, currently we're looking for modules on moneta.
That we did on this PR: https://github.com/JavaMoney/jsr354-ri/pull/135
That will be fixed on 1.2 version.
I've got a problem with resources linking in Dropwizard. With JAX-RS 2.0 we've got magical javax.ws.rs.core.Link class which with it's builder can do almost all the work for you. Unfortunately Dropwizard 0.7.1 doesn't depend on the new 2.0 API, but on the old javax.ws.rs:jsr311-api API, which can't handle linking. Or can it? This is the problem I want to solve with Dropwizard. I probably have two ways to do it and I don't know if any of them is valid:
Option 1: I add JAX-RS 2.0 dependency to my project. Voila! I've got Link. But the problem is, that it doesn't work well with old implementations from Jersey - I got AbstractMethodException from UriBuilder, which apparently changed from version 1 to 2. So the answer is to supply new implementations. Can I do it? If yes, than how can I do it? Will new implementations work with dropwizard well?
Option 2: I can just add some other resource linking to dropwizard. Is there some other linking standard/library? I can't use jersey-declarative-linking because it mixes representations with the resources (the linking takes place in representations), and I want my representations not to know a thing about resources layer. So is there another linking standard for Dropwizard, Jersey and JAX-RS 1?
I've finally found an answer to my question.
Option 2 was a dead end. There was no other jax-rs-2-like linking library to either dropwizard or jersey itself.
Option one also was hard to do, but fortunatelly yesterday dropwizard released version 0.8.0-rc1 of their framework, which depends on jersey 2, which is the implementation of JAX-RS 2.0. So for all of you that want to have HATEOAS in dropwizard, version 0.8.0 is for you.
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.