I am using ObjectMapper to convert a JSON String to a Map but I get ClassCastException when trying to retrieve a value:
Map<String,String[]> args = objectMapper.readValue(jsonString, HashMap.class);
String[] array = args.get(paramName);
then doing
String x = array[0];
gives
java.lang.ClassCastException: java.util.ArrayList cannot be cast to [Ljava.lang.String
How can this be when I clearly specify String[] and not ArrayList, and when the second line doesn't cause any errors...
String[]
to store values) but I doubt that's what you're running into here. – Roddy of the Frozen Peas Aug 21 '12 at 19:09objectMapper
returns aMap<String,ArrayList<String>>
, notMap<String,String[]>
. – dasblinkenlight Aug 21 '12 at 19:10String[] array = args.get(paramName);
) – SJuan76 Aug 21 '12 at 19:15