JSON Parser -java.lang.NoSuchFieldError: defaultReader

怎甘沉沦 提交于 2019-11-28 10:23:27

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.

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!