public Tag unmarshall(JsonUnmarshallerContext context) throws Exception {
    Tag tag = new Tag();

    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("Key", targetDepth)) {
          context.nextToken();
          tag.setKey(context.getUnmarshaller(String.class).unmarshall(context));
        }
        if (context.testExpression("Value", targetDepth)) {
          context.nextToken();
          tag.setValue(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 tag;
  }
Ejemplo n.º 2
0
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;

    if (obj instanceof Tag == false) return false;
    Tag other = (Tag) obj;
    if (other.getKey() == null ^ this.getKey() == null) return false;
    if (other.getKey() != null && other.getKey().equals(this.getKey()) == false) return false;
    if (other.getValue() == null ^ this.getValue() == null) return false;
    if (other.getValue() != null && other.getValue().equals(this.getValue()) == false) return false;
    return true;
  }