cancel
Showing results for 
Search instead for 
Did you mean: 

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

GeordieMc
Member
1 ACCEPTED SOLUTION

Accepted Solutions

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

2 REPLIES 2

I found the solution.

 

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

 

 

GeordieMc
Member

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);