public JSONValue toJSON(Object aPojo) throws MapperException { final JSONObject lObj = new JSONObject(); if(! Map.class.isAssignableFrom(aPojo.getClass())) throw new MapperException("MapMapper cannot map: " + aPojo.getClass().getName()); Map lMap = (Map) aPojo; for(Object lKey : lMap.keySet()) { lObj.getValue().put(lKey.toString(), JSONMapper.toJSON(lMap.get(lKey))); } return lObj; } }
private JSONObject marshallImplArray(Object aObj, HashMap aPool) throws MarshallException { final Class lClass = aObj.getClass(); final String lObjClassName = lClass.getName(); // Construct the component class name. String lComponentClassName = "unknown"; if(lObjClassName.startsWith("[L")) // Array of objects. lComponentClassName = lObjClassName.substring(2, lObjClassName.length() - 1); else // Array of array; Array of primitive types. lComponentClassName = lObjClassName.substring(1); final JSONObject lArrElement = new JSONObject(); lArrElement.getValue().put(RNDR_ATTR_KIND, new JSONString(RNDR_ARR)); lArrElement.getValue().put(RNDR_ATTR_CLASS, new JSONString(lComponentClassName)); final ArrayHelper lAh = new ArrayHelper(); lAh.renderValue(aObj, lArrElement, this, aPool); return lArrElement; }
private JSONObject marshallPrimitive(String aType, String aValue) { final JSONObject lElement = new JSONObject(); lElement.getValue().put(RNDR_ATTR_KIND, new JSONString(RNDR_PRIM)); lElement.getValue().put(RNDR_ATTR_TYPE, new JSONString(aType)); lElement.getValue().put(RNDR_ATTR_VALUE, new JSONString(aValue)); return lElement; }
final JSONObject lElements = new JSONObject(); String lPropName=""; try
public void renderValue(Object aObj, JSONObject aObjectElement, JSONMarshall aMarshall, HashMap aPool) throws MarshallException { // We create a new JSON array where we will collect the elements of the // map. We attach this new array as the parent object value. final JSONArray lArray = new JSONArray(); aObjectElement.getValue().put(JSONMarshall.RNDR_ATTR_VALUE, lArray); // We iterate through the keys of the map, render these as // JSON values and put these values in the array created above. final Map lMap = (Map) aObj; final Iterator lIter = lMap.keySet().iterator(); for(Object lKey : lMap.keySet()) { // Get hold of each key-value pair. final Object lValue = lMap.get(lKey); // We create a JSON object to render the key-value pairs. final JSONObject lKeyValuePair = new JSONObject(); lArray.getValue().add(lKeyValuePair); lKeyValuePair.getValue().put(ATTR_KEY, aMarshall.marshallImpl(lKey, aPool)); lKeyValuePair.getValue().put(ATTR_VALUE, aMarshall.marshallImpl(lValue, aPool)); } }
final JSONObject lElements = new JSONObject(); aObjectElement.getValue().put(JSONMarshall.RNDR_ATTR_VALUE, lElements);
private JSONObject marshallImplObject(Object aObj, String aObjId, Class aObjClass, String aObjClassName, HashMap aPool) throws MarshallException { final JSONObject lObjElement = new JSONObject(); lObjElement.getValue().put(RNDR_ATTR_KIND, new JSONString(RNDR_OBJ)); lObjElement.getValue().put(RNDR_ATTR_ID, new JSONString(aObjId)); lObjElement.getValue().put(RNDR_ATTR_CLASS, new JSONString(aObjClassName)); final MarshallHelper lHelper = repo.findHelper(aObjClass); lHelper.renderValue(aObj, lObjElement, this, aPool); return lObjElement; }
final JSONObject lElement = new JSONObject(); lElement.getValue().put(RNDR_ATTR_KIND, new JSONString(RNDR_NULL)); return lElement; final JSONObject lElement = new JSONObject(); lElement.getValue().put(RNDR_ATTR_KIND, new JSONString(RNDR_OBJREF)); lElement.getValue().put(RNDR_ATTR_REF, new JSONString((String) aPool.get(lRef)));
final JSONObject lElements = new JSONObject(); aObjectElement.getValue().put(JSONMarshall.RNDR_ATTR_VALUE, lElements);
final JSONObject lElements = new JSONObject();
final JSONObject lObj = new JSONObject(); for(Object lKey: ((Map)anObject).keySet())
public final JSONObject object( String aStreamName ) throws RecognitionException, TokenStreamException { JSONObject lResult= new JSONObject();