コード例 #1
0
 public JsonWriter name(String name) throws IOException {
   if (current == null || current.array)
     throw new IllegalStateException("Current item must be an object.");
   if (!current.needsComma) current.needsComma = true;
   else writer.write(',');
   writer.write(outputType.quoteName(name));
   writer.write(':');
   named = true;
   return this;
 }
コード例 #2
0
 public JsonWriter array() throws IOException {
   if (current != null) {
     if (current.array) {
       if (!current.needsComma) current.needsComma = true;
       else writer.write(',');
     } else {
       if (!named && !current.array) throw new IllegalStateException("Name must be set.");
       named = false;
     }
   }
   stack.add(current = new JsonObject(true));
   return this;
 }
コード例 #3
0
 public JsonWriter value(Object value) throws IOException {
   if (current != null) {
     if (current.array) {
       if (!current.needsComma) current.needsComma = true;
       else writer.write(',');
     } else {
       if (!named) throw new IllegalStateException("Name must be set.");
       named = false;
     }
   }
   if (value == null || value instanceof Number || value instanceof Boolean) {
     writer.write(String.valueOf(value));
   } else {
     writer.write(outputType.quoteValue(value.toString()));
   }
   return this;
 }