0

A little background first. I have an application that is deployed in Weblogic. It receives a Json response from a Service. I'm trying to use JsonPath to navigate the tree and I'm having an unusual issue.

I'm using Maven to build/deploy the application. Dependency:

<dependency>
  <groupId>com.jayway.restassured</groupId>
  <artifactId>json-path</artifactId>
  <version>1.8.1</version>
</dependency>

After getting it running with the full response in Junit and realizing that it wasn't working in the application when deployed, I made it simpler and hard coded a very small subset of the data.

{
    "ChangeStatus": {
        "Code": {
            "value": "1002"
        },
        "Description": {
            "value": "Matched more then 10 records"
        }
    }
}

Here's what I'm looking at right now...

String miniJson = "{\"ChangeStatus\":{\"Code\":{\"value\":\"1002\"},\"Description\":{\"value\":\"Matched more then 10 records\"}}}";
JsonPath miniJsonPath = new JsonPath(miniJson);
String statusCode = miniJsonPath.getString("ChangeStatus.Code.value");

In JUnit, this code works and I can assert 1002 successfully. In the application after pushing to weblogic, this exact code snippet does not work. It throws a NoSuchMethodError.

Any ideas would be welcome. FYI, we are on Weblogic 10.3.6

Thanks in advance!

tom redfern
  • 30,562
  • 14
  • 91
  • 126
Shino
  • 99
  • 12

2 Answers2

0

I am not an expert in Weblogic, but as an alternative you can include

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.2.0-rc1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.2.0-rc1</version>
    </dependency>

and create a class ChangeStatus with 2 members Code and Description and then you can deserialize the JSON using:

    `new ObjectMapper().readValue(miniJson, ChangeStatus.class)`  

Hope it hepls.

mihai.ciorobea
  • 741
  • 5
  • 12
  • Thanks for your feedback. I'm actually using that very code in other places in the application. The piece I'm working with right now is far more complicated than what I displayed. JsonPath is the most useful tool I've found to this point to handle the overly-nested nature of the Json I'm dealing with. I did find the solution and will post it. – Shino Aug 20 '13 at 00:41
0

What I discovered is that jsonpath depends upon antlr. Weblogic also includes this package, but I believe it is an older version.

I fixed the problem by telling Weblogic to use the classes included in the app. weblogic.xml

<wls:container-descriptor>
    <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
</wls:container-descriptor>
Shino
  • 99
  • 12