Esempio n. 1
0
  public Hit unmarshall(JsonUnmarshallerContext context) throws Exception {
    Hit hit = new Hit();

    int originalDepth = context.getCurrentDepth();
    String currentParentElement = context.getCurrentParentElement();
    int targetDepth = originalDepth + 1;

    JsonToken token = context.getCurrentToken();
    if (token == null) token = context.nextToken();
    if (token == VALUE_NULL) return null;

    while (true) {
      if (token == null) break;

      if (token == FIELD_NAME || token == START_OBJECT) {
        if (context.testExpression("id", targetDepth)) {
          context.nextToken();
          hit.setId(context.getUnmarshaller(String.class).unmarshall(context));
        }
        if (context.testExpression("fields", targetDepth)) {
          context.nextToken();
          hit.setFields(
              new MapUnmarshaller<String, java.util.List<String>>(
                      context.getUnmarshaller(String.class),
                      new ListUnmarshaller<String>(context.getUnmarshaller(String.class)))
                  .unmarshall(context));
        }
        if (context.testExpression("exprs", targetDepth)) {
          context.nextToken();
          hit.setExprs(
              new MapUnmarshaller<String, String>(
                      context.getUnmarshaller(String.class), context.getUnmarshaller(String.class))
                  .unmarshall(context));
        }
        if (context.testExpression("highlights", targetDepth)) {
          context.nextToken();
          hit.setHighlights(
              new MapUnmarshaller<String, String>(
                      context.getUnmarshaller(String.class), context.getUnmarshaller(String.class))
                  .unmarshall(context));
        }
      } else if (token == END_ARRAY || token == END_OBJECT) {
        if (context.getLastParsedParentElement() == null
            || context.getLastParsedParentElement().equals(currentParentElement)) {
          if (context.getCurrentDepth() <= originalDepth) break;
        }
      }
      token = context.nextToken();
    }

    return hit;
  }