Reply
Highlighted
Member
Posts: 7
Registered: ‎04-23-2021
Accepted Solution

ClassCastExceptions with JSON response

Hi,

 

I was wondering if anyone has experienced ClassCastException when trying to prase a JSON response.

 

I'm using Postman to run some end to end testing and thought I was getting nothing in the response, but on closer inspection a JSON message is being returned, bit it is throwing a ClassCastException. 

 

I've taken the response and used it to define some test cases to iron out any exceptions, but whenever I try end-to-end testing it throws it again.

 

Kind regards


Accepted Solutions
Solution
Accepted by topic author GeordieMc
‎05-06-2021 10:31 PM
Member
Posts: 7
Registered: ‎04-23-2021

Re: ClassCastExceptions with JSON response

By applying a regex and adding a replace all, we managed to fix the issue and were able to parse the response.

 

JSONDeserializer<Map<String, Object>> js = new JSONDeserializer<>();
pspResponseMap = js.deserialize(response.replaceAll("[\\p{C}]", ""), Map.class);

 

View solution in original post


All Replies
Member
Posts: 7
Registered: ‎04-23-2021

Re: ClassCastExceptions with JSON response

I found the solution.

 

The JSON responses starts with "ZWNBSP" character (zero width no-break space) in the response.

 

 

Solution
Accepted by topic author GeordieMc
‎05-06-2021 10:31 PM
Member
Posts: 7
Registered: ‎04-23-2021

Re: ClassCastExceptions with JSON response

By applying a regex and adding a replace all, we managed to fix the issue and were able to parse the response.

 

JSONDeserializer<Map<String, Object>> js = new JSONDeserializer<>();
pspResponseMap = js.deserialize(response.replaceAll("[\\p{C}]", ""), Map.class);