I have JSON data that look like
{"SESSIONID": 7242750700467747000}
The number was previously obtained from the server response and is created by the server side as Java Long. The client identifies itself by thinking that it is sessionID and sends it with requests. The problem is that when a client request arrives at the server, I need to parse this value again to enter Long. I am using JsonPath in particular:
<dependency> <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path-assert</artifactId> <version>0.8.1</version> <scope>test</scope> </dependency>
When I parse JSON data like this
Long sessionID = JsonPath.read (json, "$ .sessionID");
I get an exception:
java.lang.ClassCastException: java.lang.Integer cannot be passed to java.lang.Long
So it looks like the number is being processed by JsonPath as an Integer. This will undoubtedly lead to incorrect results, since Integer is less than Long. Is there a way in JsonPath to parse and return data like Long?
source share