in plugins/json/src/main/java/org/apache/struts2/json/DefaultJSONWriter.java [218:284]
protected void bean(Object object) throws JSONException {
this.add("{");
BeanInfo info;
try {
Class<?> clazz = excludeProxyProperties ? ProxyUtil.ultimateTargetClass(object) : object.getClass();
info = ((object == this.root) && this.ignoreHierarchy)
? getBeanInfoIgnoreHierarchy(clazz)
: getBeanInfo(clazz);
PropertyDescriptor[] props = info.getPropertyDescriptors();
boolean hasData = false;
for (PropertyDescriptor prop : props) {
String name = prop.getName();
Method accessor = prop.getReadMethod();
Method baseAccessor = findBaseAccessor(clazz, accessor);
if (baseAccessor != null) {
if (baseAccessor.isAnnotationPresent(JSON.class)) {
JSONAnnotationFinder jsonFinder = new JSONAnnotationFinder(baseAccessor).invoke();
if (!jsonFinder.shouldSerialize()) continue;
if (jsonFinder.getName() != null) {
name = jsonFinder.getName();
}
}
// ignore "class" and others
if (this.shouldExcludeProperty(prop)) {
continue;
}
String expr = null;
if (this.buildExpr) {
expr = this.expandExpr(name);
if (this.shouldExcludeProperty(expr)) {
continue;
}
expr = this.setExprStack(expr);
}
Object value = accessor.invoke(object);
if (baseAccessor.isAnnotationPresent(JSONFieldBridge.class)) {
value = getBridgedValue(baseAccessor, value);
}
boolean propertyPrinted = this.add(name, value, accessor, hasData);
hasData = hasData || propertyPrinted;
if (this.buildExpr) {
this.setExprStack(expr);
}
}
}
// special-case handling for an Enumeration - include the name() as
// a property */
if (object instanceof Enum) {
Object value = ((Enum) object).name();
this.add("_name", value, object.getClass().getMethod("name"), hasData);
}
} catch (Exception e) {
throw new JSONException(e);
}
this.add("}");
}