Java gson, ClassCastException on decoding to Map<String,String[]>
问题 I want to decode a json string like {"username":["emmet"]} to a Map<String,String[]> object. using following code: String json = "{\"username\":[\"emmet\"]}"; Gson gson = new GsonBuilder().create(); Map<String,String[]> map = new HashMap<>(); map = (Map<String,String[]>)gson.fromJson(json, map.getClass()); String[] val = map.get("username"); System.out.println(val); this exception occurs: Exception in thread "main" java.lang.ClassCastException: java.util.ArrayList cannot be cast to [Ljava