/** * @param o * @throws ConverterException */ public void value(Object o) throws ConverterException { o = config.getProxyHandler().unwrapIfProxy(o); try { if (o == null || o.equals(JSONObject.NULL)) { writer.value(null); } else if (o instanceof CharSequence) { writer.value(o); } else if (o instanceof Class<?>) { writer.value(((Class<?>) o).getName()); } else if ((o.getClass().isPrimitive() && !o.getClass().equals(byte[].class)) || o instanceof Number || o instanceof Boolean) { writer.value(o); } else { if (referenceStack.contains(o)) { handleCircularRelationship(o); } else { referenceStack.push(o); ObjectMarshaller<JSON> marshaller = config.getMarshaller(o); if (marshaller == null) { throw new ConverterException( "Unconvertable Object of class: " + o.getClass().getName()); } marshaller.marshalObject(o, this); referenceStack.pop(); } } } catch (ConverterException ce) { throw ce; } catch (JSONException e) { throw new ConverterException(e); } }
public ObjectMarshaller<C> getMarshaller(Object o) { ObjectMarshaller<C> marshaller = null; Integer cacheKey = null; if (!developmentMode && cacheObjectMarshallerByClass && o != null) { cacheKey = System.identityHashCode(o.getClass()); marshaller = objectMarshallerForClassCache.get(cacheKey); if (marshaller != NULL_HOLDER && marshaller != null && !marshaller.supports(o)) { marshaller = null; } } if (marshaller == null) { marshaller = root.findMarhallerFor(o); if (cacheKey != null) { objectMarshallerForClassCache.put(cacheKey, marshaller != null ? marshaller : NULL_HOLDER); } } return marshaller != NULL_HOLDER ? marshaller : null; }
public void marshalObject(Object object, C converter) throws ConverterException { om.marshalObject(object, converter); }
public boolean supports(Object object) { return om.supports(object); }