Exemple #1
0
    @SuppressWarnings("rawtypes")
    @Override
    protected Object createNode(Object key, Object value) {
      if (getCurrent() == null && stack.peek() == BuilderMode.OBJECT) {
        throw new IllegalArgumentException(
            "only call to [element { }] is allowed when creating array");
      }

      try {
        int retVal = 0;
        if (stack.peek().equals(BuilderMode.ARRAY)) {
          writeObject();
          retVal = 1;
        }
        if (value instanceof Collection) {
          Collection c = (Collection) value;
          writer.key(String.valueOf(key));
          handleCollectionRecurse(c);
        } else {
          writer.key(String.valueOf(key));
          json.convertAnother(value); // .value(value);
        }
        return retVal != 0 ? retVal : null;
      } catch (JSONException e) {
        throw new IllegalArgumentException("invalid element");
      }
    }
Exemple #2
0
    @Override
    protected Object createNode(Object name) {
      int retVal = 1;
      try {
        if (start) {
          start = false;
          writeObject();
        } else {
          if (getCurrent() == null && stack.peek() == BuilderMode.OBJECT) {
            throw new IllegalArgumentException(
                "only call to [element { }] is allowed when creating array");
          }
          if (stack.peek() == BuilderMode.ARRAY) {
            writeObject();
            retVal = 2;
          }
          writer.key(String.valueOf(name)).array();
          stack.push(BuilderMode.ARRAY);
        }
      } catch (JSONException e) {
        throw new IllegalArgumentException("invalid element");
      }

      return retVal;
    }
Exemple #3
0
 @SuppressWarnings("rawtypes")
 @Override
 protected Object createNode(Object key, Map valueMap) {
   try {
     if (stack.peek().equals(BuilderMode.OBJECT)) writer.key(String.valueOf(key));
     writer.object();
     for (Object o : valueMap.entrySet()) {
       Map.Entry element = (Map.Entry) o;
       writer.key(String.valueOf(element.getKey())); // .value(element.getValue());
       json.convertAnother(element.getValue());
     }
     writer.endObject();
     return null;
   } catch (JSONException e) {
     throw new IllegalArgumentException("invalid element");
   }
 }
Exemple #4
0
 public void property(String key, Object value) throws JSONException, ConverterException {
   writer.key(key);
   value(value);
 }