public static void main(String[] args) throws Exception { MyJSONObject o = new MyJSONObject("Person-1234", false); MyJSONObject r = new MyJSONObject("Person-1234", true); MyJSONObject f = new MyJSONObject("Person-2345", false); Array a = new Array(); a.add(f); a.add(3456); a.add(null); a.add(r); a.add(null); KVMap map = new KVMap(); map.put("k1", r); map.put("k2", f); map.put("k3", null); map.put("k4", 3456); map.put(null, 6789); f.set("name", "Mary"); f.set("age", 30); f.set("friend", r); o.set("name", "John"); o.set("age", 20); o.set("friend", f); o.set("friends", a); o.set("map", map); System.err.println(o); } }
@Override public String processServiceMethodResult(Object result, Class resultType) throws Exception { MyJSONObject root = new MyJSONObject(); if (result instanceof Entity) { Entity entity = (Entity) result; MyJSONObject entityObject = _process(entity); root.set("result", entityObject); } else if (result instanceof Collection) { if (!checkCollectionItemTypes((Collection) result, Entity.class)) throw new IllegalArgumentException("Items that are not instances of Entity found in service method result"); //noinspection unchecked ArrayList list = new ArrayList((Collection) result); MetaClass metaClass; if (!list.isEmpty()) metaClass = ((Entity) list.get(0)).getMetaClass(); else metaClass = AppBeans.get(Metadata.class).getClasses().iterator().next(); MyJSONObject.Array processed = _process(list, metaClass, null); root.set("result", processed); } else { if (result != null && resultType != Void.TYPE) { Datatype datatype = getDatatype(resultType); root.set("result", datatype != null ? datatype.format(result) : result.toString()); } else { root.set("result", null); } } return root.toString(); }
root.set("__securityToken", Base64.getEncoder().encodeToString(securityToken)); String[] filteredAttributes = BaseEntityInternalAccess.getFilteredAttributes(baseGenericIdEntity); root.set("__filteredAttributes", array); case DATATYPE: if (value != null) { root.set(property.getName(), property.getRange().asDatatype().format(value)); } else if (!DynamicAttributesUtils.isDynamicAttribute(property.getName())) { root.set(property.getName(), null); if (value != null) { root.set(property.getName(), property.getRange().asEnumeration().format(value)); } else { root.set(property.getName(), null); root.set(property.getName(), null); } else { root.set(property.getName(), encodeInstance((Entity) value, visited, property.getRange().asClass(), propertyView)); root.set(property.getName(), null); break; root.set(property.getName(), array);