Exemplo n.º 1
0
 /**
  * @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);
   }
 }
Exemplo n.º 2
0
 /** Default Constructor for a JSON Converter */
 public JSON() {
   config = initConfig();
   encoding = config != null ? config.getEncoding() : "UTF-8";
   circularReferenceBehaviour =
       config != null
           ? config.getCircularReferenceBehaviour()
           : CircularReferenceBehaviour.DEFAULT;
   prettyPrint = config != null && config.isPrettyPrint();
 }
Exemplo n.º 3
0
 public ObjectMarshaller<JSON> lookupObjectMarshaller(@SuppressWarnings("hiding") Object target) {
   return config.getMarshaller(target);
 }