JSONObject mapdata = new JSONObject();
if (_ser.getMarshallClassHints()) {
try {
obj.put(TAG_JAVACLASS, BeanUtils.getClassName(o));
} catch (JSONException e) {
throw new MarshallException("javaClass not found!", e);
}
}
try {
obj.put("map", mapdata);
state.push(o, mapdata, "map");
} catch (JSONException e) {
throw new MarshallException("Could not add map to object: " + e.getMessage(), e);
}
Object key = null;
try {
Iterator i = map.entrySet().iterator();
while (i.hasNext()) {
Map.Entry ent = (Map.Entry) i.next();
key = ent.getKey();
String keyString = key.toString(); // only support String keys
Object json = _ser.marshall(state, mapdata, ent.getValue(), keyString);
// omit the object entirely if it's a circular reference or duplicate
// it will be regenerated in the fixups phase
if (JSONSerializerController.CIRC_REF_OR_DUPLICATE != json) {
mapdata.put(keyString, json);
}
}
} catch (MarshallException e) {
throw new MarshallException("map key " + key + " " + e.getMessage(), e);
} catch (JSONException e) {
throw new MarshallException("map key " + key + " " + e.getMessage(), e);
} finally {
state.pop();
}
return obj;
}