@Override
 public void consume(JsonReader in, JsonSchemaObject object) throws IOException {
   if (in.peek() == JsonToken.BEGIN_ARRAY) {
     in.beginArray();
     final ArrayList<JsonSchemaObject> list = new ArrayList<>();
     while (in.peek() != JsonToken.END_ARRAY) {
       if (in.peek() == JsonToken.BEGIN_OBJECT) {
         list.add(readInnerObject(in));
       } else in.skipValue();
     }
     assign(list, object);
     in.endArray();
   } else in.skipValue();
 }
  @Override
  public Date read(JsonReader jsonReader) throws IOException {
    if (jsonReader.peek() == JsonToken.NULL) {
      jsonReader.nextNull();
      return null;
    }

    Date date = null;

    //        while(jsonReader.hasNext()) {
    if (jsonReader.peek().equals(JsonToken.BEGIN_OBJECT)) {
      jsonReader.beginObject();

      while (!jsonReader.peek().equals(JsonToken.END_OBJECT)) {
        JsonToken token = jsonReader.peek();
        switch (token) {
          case NAME:
            if (jsonReader.nextName().equals("$date")) {
              date = getDateFromString(jsonReader.nextString());
            }
            break;
          default:
            jsonReader.skipValue();
        }
      }
      jsonReader.endObject();
    }
    //      }

    return date;
  }
 public static Set<String> fromString(String str) {
   TreeSet<String> result = new TreeSet<String>();
   if (str == null || str.isEmpty()) {
     return result;
   }
   try {
     JsonReader reader = new JsonReader(new StringReader(str));
     reader.beginObject();
     while (reader.hasNext()) {
       String key = reader.nextName();
       if (JSON_STARRED_SESSIONS_KEY.equals(key)) {
         reader.beginArray();
         while (reader.hasNext()) {
           result.add(reader.nextString());
         }
         reader.endArray();
       } else {
         reader.skipValue();
       }
     }
     reader.endObject();
     reader.close();
   } catch (Exception ex) {
     Log.w(TAG, "Ignoring invalid remote content.", ex);
     return null;
   }
   return result;
 }
  private Dependency readDependency(JsonReader in) throws IOException {
    DefaultDependency dep = new DefaultDependency();

    in.beginObject();
    while (in.hasNext()) {
      String name = in.nextName();
      switch (name) {
        case PACKAGE_PROPERTY:
          dep.setPackage(in.nextString());
          break;
        case VERSION_PROPERTY:
          dep.setVersion(in.nextString());
          break;
        case DEPENDNCY_OP_PROPERTY:
          dep.setDependencyOperator(RelationOperator.valueOf(in.nextString()));
          break;
        case ALTERNATIVES_PROPERTY:
          in.beginArray();
          while (in.hasNext()) {
            dep.getAlternatives().add(readDependency(in));
          }
          in.endArray();
          break;
        default:
          in.skipValue();
          break;
      }
    }
    in.endObject();

    return dep;
  }
    @Override
    public T read(JsonReader in) throws IOException {
      if (in.peek() == JsonToken.NULL) {
        in.nextNull();
        return null;
      }

      T instance = constructor.construct();

      try {
        in.beginObject();
        while (in.hasNext()) {
          String name = in.nextName();
          BoundField field = boundFields.get(name);
          if (field == null || !field.deserialized) {
            in.skipValue();
          } else {
            field.read(in, instance);
          }
        }
      } catch (IllegalStateException e) {
        throw new JsonSyntaxException(e);
      } catch (IllegalAccessException e) {
        throw new AssertionError(e);
      }
      in.endObject();
      return instance;
    }
 @Override
 public void consume(JsonReader in, JsonSchemaObject object) throws IOException {
   if (in.peek() == JsonToken.NUMBER) {
     readNumber(in, object);
   } else {
     in.skipValue();
   }
 }
 @Override
 public void consume(JsonReader in, JsonSchemaObject object) throws IOException {
   if (in.peek() == JsonToken.BOOLEAN) {
     assign(in.nextBoolean(), object);
   } else {
     in.skipValue();
   }
 }
    @Override
    public TimeSeries<Location> read(JsonReader in) throws IOException {
      if (gson == null) {
        gson = Vinli.curApp().gson();
      }

      final TimeSeries.Builder<Location> b =
          new AutoParcel_TimeSeries.Builder<Location>().type(TIME_SERIES_TYPE);

      in.beginObject();
      while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
          case "meta":
            b.meta(gson.<TimeSeries.Meta>fromJson(in, TimeSeries.Meta.class));
            break;
          case "locations":
            in.beginObject();
            while (in.hasNext()) {
              final String locName = in.nextName();

              switch (locName) {
                case "type":
                  in.skipValue();
                  break;
                case "features":
                  final List<Location> locations = new ArrayList<>();

                  in.beginArray();
                  while (in.hasNext()) {
                    locations.add(gson.<Location>fromJson(in, Location.class));
                  }
                  in.endArray();

                  b.items(locations);
                  break;
                default:
                  throw new JsonParseException(
                      "unrecognized key '" + locName + "' while parsing locations");
              }
            }
            in.endObject();
            break;
          default:
            throw new JsonParseException("unrecognized key '" + name + "' while parsing locations");
        }
      }
      in.endObject();

      return b.build();
    }
 void readSingleDefinition(JsonReader in, String name, JsonSchemaObject object)
     throws IOException {
   if (in.peek() != JsonToken.BEGIN_OBJECT) {
     in
         .skipValue(); // if unknown property has non-object value, than it is not a definition,
                       // lets ignore it
     return;
   }
   final JsonSchemaObject defined = read(in);
   if (defined == null) return;
   Map<String, JsonSchemaObject> definitions = object.getDefinitions();
   if (definitions == null) {
     object.setDefinitions(definitions = new HashMap<>());
   }
   definitions.put(name, defined);
 }
  @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
  public String importData(Reader in, Model m) throws IOException {

    JsonReader reader = new JsonReader(in);

    reader.beginObject();

    while (reader.hasNext()) {
      JsonToken tok = reader.peek();
      switch (tok) {
        case NAME:
          String name = reader.nextName();
          if (name.equals(MITREidDataService.MITREID_CONNECT_1_0)) {
            dataService_1_0.importData(reader);
          } else if (name.equals(MITREidDataService.MITREID_CONNECT_1_1)) {
            dataService_1_1.importData(reader);
          } else if (name.equals(MITREidDataService.MITREID_CONNECT_1_2)) {
            dataService_1_2.importData(reader);
          } else if (name.equals(MITREidDataService.MITREID_CONNECT_1_3)) {
            dataService_1_3.importData(reader);
          } else {
            // consume the next bit silently for now
            logger.debug("Skipping value for " + name); // TODO: write these out?
            reader.skipValue();
          }
          break;
        case END_OBJECT:
          reader.endObject();
          break;
        case END_DOCUMENT:
          break;
      }
    }

    return "httpCodeView";
  }
    @Override
    public Location read(JsonReader in) throws IOException {
      if (gson == null) {
        gson = Vinli.curApp().gson();
      }

      final Location.Builder b = new AutoParcel_Location.Builder();

      in.beginObject();
      while (in.hasNext()) {
        final String locationName = in.nextName();

        switch (locationName) {
          case "type":
            in.skipValue();
            break;
          case "geometry":
            in.beginObject();
            while (in.hasNext()) {
              final String geoName = in.nextName();

              switch (geoName) {
                case "type":
                  in.skipValue();
                  break;
                case "coordinates":
                  b.coordinate(gson.<Coordinate>fromJson(in, Coordinate.class));
                  break;
                default:
                  throw new JsonParseException("unknown location geometry key " + geoName);
              }
            }
            in.endObject();
            break;
          case "properties":
            in.beginObject();
            while (in.hasNext()) {
              final String propName = in.nextName();

              switch (propName) {
                case "id":
                  b.id(in.nextString());
                  break;
                case "timestamp":
                  b.timestamp(in.nextString());
                  break;
                case "links":
                  in.skipValue();
                  break;
                default:
                  throw new JsonParseException("unknown location geometry key " + propName);
              }
            }
            in.endObject();
            break;
          default:
            throw new JsonParseException("unknown location key " + locationName);
        }
      }
      in.endObject();

      return b.build();
    }