mirror of
https://github.com/alibaba/fastjson.git
synced 2026-10-29 14:10:25 +08:00
bug fixed for toJSON
This commit is contained in:
@@ -525,7 +525,10 @@ public abstract class JSON implements JSONStreamAware, JSONAware {
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
javaBeanSerializer.getFieldValues(javaObject, json);
|
||||
Map<String, Object> values = javaBeanSerializer.getFieldValuesMap(javaObject);
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
json.put(entry.getKey(), toJSON(entry.getValue()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new JSONException("toJSON error", e);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -602,9 +603,13 @@ public class JavaBeanSerializer implements ObjectSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
public void getFieldValues(Object object, Map<String, Object> outMap) throws Exception {
|
||||
public Map<String, Object> getFieldValuesMap(Object object) throws Exception {
|
||||
Map<String, Object> map = new LinkedHashMap<String, Object>(sortedGetters.length);
|
||||
|
||||
for (FieldSerializer getter : sortedGetters) {
|
||||
outMap.put(getter.fieldInfo.name, getter.getPropertyValue(object));
|
||||
map.put(getter.fieldInfo.name, getter.getPropertyValue(object));
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user