BeanData bd;
try {
bd = getBeanData(o.getClass());
}
catch (IntrospectionException e) {
throw new MarshallException(o.getClass().getName() + " is not a bean", e);
}
JSONObject val = new JSONObject();
if (ser.getMarshallClassHints()) {
try {
val.put("javaClass", o.getClass().getName());
}
catch (JSONException e) {
throw new MarshallException("JSONException: " + e.getMessage(), e);
}
}
Object args[] = new Object[0];
Object result;
for (Map.Entry<String, Method> ent : bd.readableProps.entrySet()) {
String prop = ent.getKey();
Method getMethod = ent.getValue();
if (log.isDebugEnabled()) {
log.debug("invoking " + getMethod.getName() + "()");
}
try {
result = getMethod.invoke(o, args);
}
catch (Throwable e) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
throw new MarshallException("bean " + o.getClass().getName() + " can't invoke " + getMethod.getName() + ": " + e.getMessage(), e);
}
try {
if (result != null || ser.getMarshallNullAttributes()) {
try {
Object json = ser.marshall(state, o, result, prop);
val.put(prop, json);
}
catch (JSONException e) {
throw new MarshallException("JSONException: " + e.getMessage(), e);
}
}
}
catch (MarshallException e) {
throw new MarshallException("bean " + o.getClass().getName() + " " + e.getMessage(), e);
}
}
return val;
}