org.apache.struts2.json.JSONException: Incompatible types for property
Use the source, Luke. If you look at the class throwing that exception, you'll find that it doesn't support List<anything[]>
. The relevant lines from org.apache.struts2.json.JSONPopulator.convertToCollection()
:
232 // create an object for each element233 for (int j = 0; j < values.size(); j++) {234 Object listValue = values.get(j);235 236 if (itemClass.equals(Object.class)) {237 // Object[]238 newCollection.add(listValue);239 } else if (isJSONPrimitive(itemClass)) {240 // primitive array241 newCollection.add(this.convertPrimitive(itemClass, listValue, accessor));242 } else if (Map.class.isAssignableFrom(itemClass)) {243 Object newObject = convertToMap(itemClass, itemType, listValue, accessor);244 newCollection.add(newObject);245 } else if (List.class.isAssignableFrom(itemClass)) {246 Object newObject = convertToCollection(itemClass, itemType, listValue, accessor);247 newCollection.add(newObject);248 } else if (listValue instanceof Map) {249 // array of beans250 Object newObject = itemClass.newInstance();251 this.populateObject(newObject, (Map) listValue);252 newCollection.add(newObject);253 } else254 throw new JSONException("Incompatible types for property " + accessor.getName());255 }
This code is adding items to the list, and falls through a series of type checks before deciding how to instantiate an object from the data. The comment on line 237 is misleading; it appears to have been copied and pasted from convertToArray
; all it does is add the current listValue to the list. Similarly the comment on line 249 about an array isn't creating one either. In fact, there's no code in here to handle an array, so it drops through to line 254 and throws the exception you see. The code appears to be missing a couple of lines, like this:
else if (itemClass.isArray()) { Object newObject = convertToArray(itemClass, itemType, listValue, method); newCollection.add(newObject);
...translating pretty directly from the code in convert()
for handling one dimensional arrays - which, as you noticed, work. You'd have to ask the struts developers if this is an oversight or deliberate. It does look like you're stuck with collections of collections.
You are mapping parameters incorrectly the correct mapping would be
@SMDMethodpublic String insertZoneCharges(@SMDMethodParameter(name="list")Object[] list)