LocalPageResponse localPageResponse = createLocalPageService.createLocalPage(filePath);
Gson finalResponse = new Gson();
response.getWriter().print(finalResponse.toJson(localPageResponse));
List<String> outputLogs = new ArrayList<>();
this is piece of code from servlet , while writing test class for same , not able to pass this "Gson finalResponse = new Gson()" line od code and showing error like
java.lang.NoClassDefFoundError: com/google/gson/internal/bind/JsonTreeReader
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at javassist.runtime.Desc.getClassObject(Desc.java:43)
at javassist.runtime.Desc.getClassType(Desc.java:152)
at javassist.runtime.Desc.getType(Desc.java:122)
at javassist.runtime.Desc.getType(Desc.java:78)
......
I am trying to execute the test class, has anyone faced the same issue and if yes, how was it resolved?
Solved! Go to Solution.
Views
Replies
Total Likes
The version of Gson dependency - com.google.gson in code may need to be updated or add the dependency if missing with the test scope. The error says that the JsonTreeReader class is not available in the classpath to execute the test.
There is this thread clearly explains on the NoClassDefFoundError - https://stackoverflow.com/questions/17973970/how-can-i-solve-java-lang-noclassdeffounderror
The version of Gson dependency - com.google.gson in code may need to be updated or add the dependency if missing with the test scope. The error says that the JsonTreeReader class is not available in the classpath to execute the test.
There is this thread clearly explains on the NoClassDefFoundError - https://stackoverflow.com/questions/17973970/how-can-i-solve-java-lang-noclassdeffounderror
What is gson dependency version in your parent pom?
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>provided</scope>
</dependency>
Try to update the gson to this or higher and see if its working?
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies