FasterXML / jackson-datatype-jsr353

(DEPRECATED) -- moved under `jackson-datatypes-misc` https://github.com/FasterXML/jackson-datatypes-misc/
19 stars 14 forks source link

java.lang.ClassNotFoundException: org.glassfish.json.JsonProviderImpl #6

Closed xfeep closed 9 years ago

xfeep commented 9 years ago

I just run a simple example from its document.

        mapper = new ObjectMapper();
        mapper.registerModule(new JSR353Module());
javax.json.JsonException: Provider org.glassfish.json.JsonProviderImpl not found
    at javax.json.spi.JsonProvider.provider(JsonProvider.java:97)
    at com.fasterxml.jackson.datatype.jsr353.JSR353Module.<init>(JSR353Module.java:26)
    at com.cnebula.common.remote.core.rest.JacksonBinding.<init>(JacksonBinding.java:80)
    at ......
Caused by: java.lang.ClassNotFoundException: org.glassfish.json.JsonProviderImpl
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at jajackson-datatype-jsr353va.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:171)
    at javax.json.spi.JsonProvider.provider(JsonProvider.java:94)
    ... 25 more

My jars

jackson-annotations-2.4.0.jar
jackson-core-2.4.0.jar
jackson-databind-2.4.0.jar
jackson-datatype-jsr353-2.4.0.jar
javax.json-api-1.0.jar
xfeep commented 9 years ago

After add

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.json</artifactId>
    <version>1.0.4</version>
</dependency>

It run successfully. But I can not understand that why this dependency is not included by jackson-datatype-jsr353.

cowtowncoder commented 9 years ago

The reason is that there are multiple possible implementations, and datatype module does not want to enforce use of specific one. Assumption is that user should already have an implementation to use, as otherwise JSR-353 does not make much sense. That is, Jackson is all around superior for JSON processing in general, and this module would only be used if some other code is already using JSR-353 implementation for something.

But I agree in that README should explain this dependency and why it may be needed.

cowtowncoder commented 9 years ago

Another note: I think the error message also indicates that API jar is bit flawed -- it really should not assume a default implementation, and should rather say it can not locate an implementation. But that's JSR-353 api bug and not something module can do much about.

xfeep commented 9 years ago

@cowtowncoder Thank you!

CLEANCODEUSA commented 6 years ago

Can you mention where you have added the above code? Thanks

cowtowncoder commented 6 years ago

@Vanbeek56 xml above would go in pom.xml of Maven setup. For other build systems dependency needs to be added simlarly.