private void writeReference(Object object, JSONContext context) { TypeContext typeContext= context.writeOpenObject(); context.writeName("@ref"); context.write(context.getReferences().get(System.identityHashCode(object)) + ""); context.writeCloseObject(); }
public void writeName(String name) { if (prettyPrint) writeIndent(); if (name != null) writeQuoted(name); else write("null"); out.write(":"); if (prettyPrint) out.write(" "); }
/** * This is the default tranformer for handling nulls. This class * functions according to the JSON specification. * * @param object * @return */ public void transform(Object object) { getContext().write("null"); }
Integer objectId= getObjectId(object, context); context.getReferences().put(System.identityHashCode(object), objectId); context.write("" + objectId);
public void transform(Object object) { getContext().write(String.valueOf(((Date) object).getTime())); }
public void transform(Object object) { getContext().write(object.toString()); }
public void transform(Object object) { getContext().write(((Boolean) object) ? "true" : "false"); }
public void transform(Object value) { String val= value.toString(); getContext().write("\""); for (int i= 0; i < val.length(); ++i) { int intVal= (int) val.charAt(i); if (htmlEntities.containsKey(intVal)) { getContext().write(htmlEntities.get(intVal)); } else if (intVal > 128) { getContext().write("&#"); getContext().write(String.valueOf(intVal)); getContext().write(";"); } else { getContext().write(String.valueOf(val.charAt(i))); } } getContext().write("\""); } }