Skip to content
Advertisement

java.lang.NoSuchMethodError: org.json.JSONObject.(Ljava/lang/Object;)V

I have a basic SpringBoot 2.1.5.RELEASE app. Using Spring Initializer, JPA, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR file with some RestControllers.

In 1 of the controller this is the body I send:

JavaScript

so I create this class to send it as a RequestBody:

JavaScript

and

public class HotelswitchHotelOrderRequestBody {

JavaScript

and

JavaScript

But i have this error:

JavaScript

pom.xml:

JavaScript

Advertisement

Answer

It looks like you have more than one org.json:json dependency on your classpath.

Looking at it:

org.springframework.boot:spring-boot-starter-test depends on

com.jayway.jsonpath:json-path which in turn brings

org.json:json which is may be newer/older than the version on which

io.jsonwebtoken jjwt 0.9.1 is dependent on

You could try excluding this transitive dependency from spring-boot-starter-test/io.jsonwebtoken:

JavaScript

OR/AND

JavaScript

But it’s possible that there is something within json-path which depends on something from the older json library, which is no longer in the newer version, so proceed with caution and test everything thoroughly. There is also a chance that something else brings org.json:json.

To verify, please run mvn dependency:tree and search in the produced output for org.json:json.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement