JSON Parser -java.lang.NoSuchFieldError: defaultReader
Asked Answered
C

4

5

I am using a JSON parser to extract the value and I am using the following jar json-path-2.1.0, and I am getting the following error when I invoke the use case deployed as webservice on weblogic server I wrote a small main program to extract the value from the json string and it works fine, but the server version of the use case is giving the issue. I am not sure if there are any other jars part of my ear can negatively impact this

SEVERE: defaultReader
java.lang.NoSuchFieldError: defaultReader
at com.jayway.jsonpath.spi.json.JsonSmartJsonProvider.<init>(JsonSmartJsonProvider.java:39)
at com.jayway.jsonpath.internal.DefaultsImpl.jsonProvider(DefaultsImpl.java:21)
at com.jayway.jsonpath.Configuration.defaultConfiguration(Configuration.java:174)
at com.jayway.jsonpath.internal.JsonContext.<init>(JsonContext.java:52)
at com.jayway.jsonpath.JsonPath.parse(JsonPath.java:596)
Comedian answered 4/12, 2016 at 1:12 Comment(1)
Hey , even i am facing the same issue, but i am using the same with Spark. i am not sure how to use the following settings in my module. If you have another fix , please do let me know.Sastruga
S
9

Stumbled about the same problem.

The reason why it does not work is not the JDK 8. The reason why you encounter this issue, is the fact that weblogic 12.2.1.X is bundling some old version of json-smart.

On my machine this would be found here: jar:file:/C:/dev/WLS_12_2_1_2_0/oracle_common/modules/net.minidev.json-smart.jar!/net/minidev/json/JSONValue.class

Now if you are using a library like json-path that depends on json-smart, then by default the container will load the required class using one of its built-in modules.

The blowup you have, seems to be that the JSONValue class that your json-path depends on seemed to have this defaultReder field. Here is a snipet of the clode that is blowing up.

 public JsonSmartJsonProvider() {
        this(JSONParser.MODE_PERMISSIVE, JSONValue.defaultReader.DEFAULT_ORDERED);
    }

That

JSONValue.defaultReader

Seems not to be valid on weblogs older system class loader class.

You can tell the container to use what you are packing by putting into your weblogic.xml deployment descriptor something like this:

<wls:prefer-application-packages>       
<wls:package-name>net.minidev.json.*</wls:package-name>                              
</wls:prefer-application-packages>

I am having quite a bit of trouble getting weblogic to swallow the fine-grained instruction above. I found myself to force weblogic to swallog all that goes into the web-inf folder instead doing:

 <wls:container-descriptor>
        <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>        
    </wls:container-descriptor>

I would have rather not be using a hammer like the web-inf-classes, but I am dancing with the weblogic system classloader when I do not go coarse grained...

Regards.

Sauterne answered 10/1, 2017 at 16:0 Comment(8)
hi @Sauterne : I am using jayaway jsonpath in my spark RDD operations. Getting the same error. Not sure why this error is coming.Sastruga
Try to put a debug breakpoint near where the code explodes. Then do something like this.getClass().getResource("write in there the /path/to/your/class.class") and figure out from which location the class loader loaded the class. Confirm if it is using the library your source needs to have being used live or not. This type of error normally implies that Library A needs version A but your runtime system busines Version B... Once you figure out the versioning problem, you need to find magic tricks to get the right version to be used.Sauterne
Hi @Sauterne - I tried to print the version of the JsonPath class i am using. When i am running in eclipse, i get the right version number printed , but when i trying to create a Jar and run it through spark submit it shows version as null. Not sure which place it is getting missed out. I am using normal Jar creation using export and then choosing Extract Required Libraries into Generated JarSastruga
I am tried to use classpath checker and there are no duplicate classes for the JsonPath. Not sure where to check to fix this.Sastruga
Hi Sam, this is a mathematical thing right? So poin 1. you need to put a breakpoint in the closes position to the source code explositon possible. When you have your breakpoint working, you will be inside of a class like JsonSmartJsonProvider. Then you search your classpath for the URL of your JsonSmartJsonProvider. And you see EXACTLY where that class is coming from from which JAR on which version. And you know OK - my class loader is using exactly this version. You get the source code for itSauterne
E.g. jar-download.com/artifacts/com.jayway.jsonpath/json-path/2.4.0/… THen you see what the source code looks like. For example: JSONValue.defaultReader. BUt you have a blow up telling you NO SUCH FIELD. Ok. So how can this be? If the source code is 100% compatible the field must be there. So now you use the ClassPath search reasource to find the path for the JSONValue. YOu see EXACTLY where the JSONValue is coming from. Which JAR on which version.Sauterne
Either the classes are in the classpath and the versions make sense or not. It is a 100% mathematical thing this debugging. You just need to get to the bottom of what classes are loaded by your class loader, where they are coming from and what versions thoses jars containing the class files are presented. And the typical thing is the class loader is using a JAR file you did not expect to be there... and you have more than on jar file for the same library making a total mess. It is a mathematical problem... make sure the versions make sense.Sauterne
Thanks for the brief writting. i will check it once more.Sastruga
S
3

I too was facing this issue, It turned out some other library was using json-smart's older version, and it was getting precedence over json-path's json-smart dependency. Removing the other jar solved the issue. Or you can also downgrade your json-path's version to appropriate version such that it support json-smart's older version.

Surfboarding answered 18/12, 2017 at 13:26 Comment(3)
Hi @best Wishes : I tried to print the version of the JsonPath class i am using. When i am running in eclipse, i get the right version number printed , but when i trying to create a Jar and run it through spark submit it shows version as null. Not sure which place it is getting missed out. I am using normal Jar creation using export and then choosing Extract Required Libraries into Generated Jar. Is there something you can add more to point me in the right directionSastruga
are you using maven?Surfboarding
Yes i am using Maven for downloading the required Jar files. @best wishesSastruga
C
1

Looks like JsonParser jar is present in JVM 1.8 version and it seems to have more precedence over the JsonParser class available in Json-path.jar. Apparently the us case doesn't work in 12.2.1 version of the weblogic server but it works fine in 12.1.3

Comedian answered 7/12, 2016 at 13:48 Comment(1)
Hi @Comedian : I tried to print the version of the JsonPath class i am using. When i am running in eclipse, i get the right version number printed , but when i trying to create a Jar and run it through spark submit it shows version as null. Not sure which place it is getting missed out. I am using normal Jar creation using export and then choosing Extract Required Libraries into Generated Jar. Is there something you can add more to point me in the right directionSastruga
P
0

I had the same problem but I use Gradle so I had to add:

compile group: 'net.minidev', name: 'json-smart', version: '2.3' to my dependencies.

Pneumatology answered 4/6, 2018 at 5:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.