@param object @return
(Object object)
| 121 | * @return |
| 122 | */ |
| 123 | public static String toJSONString(Object object) { |
| 124 | JSONStringer stringer = new JSONStringer(); |
| 125 | try { |
| 126 | if (object instanceof JSONSerializable) { |
| 127 | stringer.object(); |
| 128 | ((JSONSerializable) object).toJSON(stringer); |
| 129 | stringer.endObject(); |
| 130 | } else if (object != null) { |
| 131 | Class<?> clazz = object.getClass(); |
| 132 | // stringer.key(clazz.getSimpleName()); |
| 133 | JSONUtil.writeFieldValue(stringer, clazz, object); |
| 134 | } |
| 135 | } catch (JSONException e) { |
| 136 | throw new RuntimeException(e); |
| 137 | } |
| 138 | return (stringer.toString()); |
| 139 | } |
| 140 | |
| 141 | public static <T extends JSONSerializable> T fromJSONString(T t, String json) { |
| 142 | try { |