com.fasterxml.jackson.databind.JsonNode.equals()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(153)

本文整理了Java中com.fasterxml.jackson.databind.JsonNode.equals()方法的一些代码示例,展示了JsonNode.equals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.equals()方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:equals

JsonNode.equals介绍

[英]Equality for node objects is defined as full (deep) value equality. This means that it is possible to compare complete JSON trees for equality by comparing equality of root nodes.

Note: marked as abstract to ensure all implementation classes define it properly and not rely on definition from java.lang.Object.
[中]节点对象的相等定义为完全(深度)值相等。这意味着可以通过比较根节点的相等性来比较完整的JSON树的相等性。
注意:标记为抽象以确保所有实现类都正确定义它,而不依赖于java的定义。lang.Object。

代码示例

代码示例来源:origin: aws/aws-sdk-java

/**
 * Checks whether lhs is equal to rhs
 *
 * @param lhs Lhs expression
 * @param rhs Rhs expression
 * @return True if lhs is equal to rhs;
 * False otherwise
 */
@Override
public boolean matches(JsonNode lhs, JsonNode rhs) {
  return lhs.equals(rhs);
}

代码示例来源:origin: aws/aws-sdk-java

/**
   * Checks whether lhs is not equal to rhs
   *
   * @param lhs Lhs expression
   * @param rhs Rhs expression
   * @return True if lhs is not equal to rhs;
   * False otherwise
   */
  @Override
  public boolean matches(JsonNode lhs, JsonNode rhs) {
    return !lhs.equals(rhs);
  }
}

代码示例来源:origin: aws/aws-sdk-java

/**
   * Path matcher that checks if the final result
   * matches the expected result
   *
   * @param expectedResult Expected result given by the waiter definition
   * @param finalResult    Final result of the resource got by the execution
   *                       of the JmesPath expression given by the waiter
   *                       definition
   * @return True if the final result matches the expected result,
   * False otherwise
   */
  public static boolean path(JsonNode expectedResult, JsonNode finalResult) {
    return finalResult.equals(expectedResult);
  }
}

代码示例来源:origin: redisson/redisson

@Override
public boolean equals(Comparator<JsonNode> comparator, JsonNode o)
{
  if (!(o instanceof ArrayNode)) {
    return false;
  }
  ArrayNode other = (ArrayNode) o;
  final int len = _children.size();
  if (other.size() != len) {
    return false;
  }
  List<JsonNode> l1 = _children;
  List<JsonNode> l2 = other._children;
  for (int i = 0; i < len; ++i) {
    if (!l1.get(i).equals(comparator, l2.get(i))) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: redisson/redisson

@Override
public boolean equals(Comparator<JsonNode> comparator, JsonNode o)
{
  if (!(o instanceof ObjectNode)) {
    return false;
  }
  ObjectNode other = (ObjectNode) o;
  Map<String, JsonNode> m1 = _children;
  Map<String, JsonNode> m2 = other._children;
  final int len = m1.size();
  if (m2.size() != len) {
    return false;
  }
  for (Map.Entry<String, JsonNode> entry : m1.entrySet()) {
    JsonNode v2 = m2.get(entry.getKey());
    if ((v2 == null) || !entry.getValue().equals(comparator, v2)) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * If subject is an array, this function returns true if
 * one of the elements in the array is equal to the provided search
 * value.
 *
 * @param subject Array
 * @param search  JmesPath expression
 * @return True array contains search;
 * False otherwise
 */
private static BooleanNode doesArrayContain(JsonNode subject, JsonNode search) {
  Iterator<JsonNode> elements = subject.elements();
  while (elements.hasNext()) {
    if (elements.next().equals(search)) {
      return BooleanNode.TRUE;
    }
  }
  return BooleanNode.FALSE;
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * PathAll matcher that checks if each element of the final
 * result matches the expected result
 *
 * @param expectedResult Expected result given by the waiter definition
 * @param finalResult    Final result of the resource got by the execution
 *                       of the JmesPath expression given by the waiter
 *                       definition
 * @return True if all elements of the final result matches
 * the expected result, False otherwise
 */
public static boolean pathAll(JsonNode expectedResult, JsonNode finalResult) {
  if (finalResult.isNull()) {
    return false;
  }
  if (!finalResult.isArray()) {
    throw new RuntimeException("Expected an array");
  }
  for (JsonNode element : finalResult) {
    if (!element.equals(expectedResult)) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * PathAny matcher that checks if any element of the final
 * result matches the expected result
 *
 * @param expectedResult Expected result given by the waiter definition
 * @param finalResult    Final result of the resource got by the execution
 *                       of the JmesPath expression given by the waiter
 *                       definition
 * @return True if any single element of the final result matches
 * the expected result, False if none matched
 */
public static boolean pathAny(JsonNode expectedResult, JsonNode finalResult) {
  if (finalResult.isNull()) {
    return false;
  }
  if (!finalResult.isArray()) {
    throw new RuntimeException("Expected an array");
  }
  for (JsonNode element : finalResult) {
    if (element.equals(expectedResult)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: apache/avro

/**
 * Adds a property with the given name <tt>name</tt> and
 * value <tt>value</tt>. Neither <tt>name</tt> nor <tt>value</tt> can be
 * <tt>null</tt>. It is illegal to add a property if another with
 * the same name but different value already exists in this schema.
 *
 * @param name The name of the property to add
 * @param value The value for the property to add
 */
private void addProp(String name, JsonNode value) {
 if (reserved.contains(name))
  throw new AvroRuntimeException("Can't set reserved property: " + name);
 if (value == null)
  throw new AvroRuntimeException("Can't set a property to null: " + name);
 JsonNode old = props.putIfAbsent(name,  value);
 if (old != null && !old.equals(value)) {
  throw new AvroRuntimeException("Can't overwrite property: " + name);
 }
}

代码示例来源:origin: docker-java/docker-java

@Override
  public ExposedPort deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    if (!node.equals(NullNode.getInstance())) {
      Entry<String, JsonNode> field = node.fields().next();
      return ExposedPort.parse(field.getKey());
    } else {
      return null;
    }
  }
}

代码示例来源:origin: apache/avro

private boolean defaultValueEquals(JsonNode thatDefaultValue) {
 if (defaultValue == null)
  return thatDefaultValue == null;
 if (thatDefaultValue == null)
  return false;
 if (Double.isNaN(defaultValue.doubleValue()))
  return Double.isNaN(thatDefaultValue.doubleValue());
 return defaultValue.equals(thatDefaultValue);
}

代码示例来源:origin: stackoverflow.com

public boolean equals(Object o)
{
  if (o == this) return true;
  if (o == null) return false;
  if (o.getClass() != getClass()) {
    return false;
  }
  ObjectNode other = (ObjectNode) o;
  if (other.size() != size()) {
    return false;
  }
  if (_children != null) {
    for (Map.Entry<String, JsonNode> en : _children.entrySet()) {
      String key = en.getKey();
      JsonNode value = en.getValue();

      JsonNode otherValue = other.get(key);

      if (otherValue == null || !otherValue.equals(value)) {
        return false;
      }
    }
  }
  return true;
}

代码示例来源:origin: docker-java/docker-java

@Override
  public ExposedPorts deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {
    List<ExposedPort> exposedPorts = new ArrayList<ExposedPort>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {
      Map.Entry<String, JsonNode> field = it.next();
      if (!field.getValue().equals(NullNode.getInstance())) {
        exposedPorts.add(ExposedPort.parse(field.getKey()));
      }
    }
    return new ExposedPorts(exposedPorts.toArray(new ExposedPort[0]));
  }
}

代码示例来源:origin: docker-java/docker-java

@Override
  public Links deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {
    final List<Link> binds = new ArrayList<Link>();
    final ObjectCodec oc = jsonParser.getCodec();
    final JsonNode node = oc.readTree(jsonParser);
    for (final Iterator<JsonNode> it = node.elements(); it.hasNext();) {
      final JsonNode element = it.next();
      if (!element.equals(NullNode.getInstance())) {
        binds.add(Link.parse(element.asText()));
      }
    }
    return new Links(binds.toArray(new Link[0]));
  }
}

代码示例来源:origin: docker-java/docker-java

@Override
  public Volumes deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {
    List<Volume> volumes = new ArrayList<Volume>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {
      Map.Entry<String, JsonNode> field = it.next();
      if (!field.getValue().equals(NullNode.getInstance())) {
        String path = field.getKey();
        Volume volume = new Volume(path);
        volumes.add(volume);
      }
    }
    return new Volumes(volumes.toArray(new Volume[0]));
  }
}

代码示例来源:origin: dreamhead/moco

private boolean doMatch(final Request request, final MessageContent content) {
  try {
    JsonNode requestNode = mapper.readTree(content.toString());
    JsonNode resourceNode = mapper.readTree(expected.readFor(of(request)).toString());
    return requestNode.equals(resourceNode);
  } catch (JsonProcessingException jpe) {
    return false;
  } catch (IOException e) {
    throw new MocoException(e);
  }
}

代码示例来源:origin: docker-java/docker-java

@Override
  public VolumeBinds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {
    List<VolumeBind> binds = new ArrayList<VolumeBind>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {
      Map.Entry<String, JsonNode> field = it.next();
      JsonNode value = field.getValue();
      if (!value.equals(NullNode.getInstance())) {
        if (!value.isTextual()) {
          throw deserializationContext.mappingException("Expected path for '" + field.getKey()
              + "'in host but got '" + value + "'.");
        }
        VolumeBind bind = new VolumeBind(value.asText(), field.getKey());
        binds.add(bind);
      }
    }
    return new VolumeBinds(binds.toArray(new VolumeBind[binds.size()]));
  }
}

代码示例来源:origin: docker-java/docker-java

@Override
  public VolumeRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    if (!node.equals(NullNode.getInstance())) {
      Entry<String, JsonNode> field = node.fields().next();
      String volume = field.getKey();
      AccessMode accessMode = AccessMode.fromBoolean(field.getValue().asBoolean());
      return new VolumeRW(new Volume(volume), accessMode);
    } else {
      return null;
    }
  }
}

代码示例来源:origin: docker-java/docker-java

@Override
  public VolumesRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {
    List<VolumeRW> volumesRW = new ArrayList<VolumeRW>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {
      Map.Entry<String, JsonNode> field = it.next();
      JsonNode value = field.getValue();
      if (!value.equals(NullNode.getInstance())) {
        if (!value.isBoolean()) {
          throw deserializationContext.mappingException("Expected access mode for '" + field.getKey()
              + "' in host but got '" + value + "'.");
        }
        VolumeRW bind = new VolumeRW(new Volume(field.getKey()), AccessMode.fromBoolean(value.asBoolean()));
        volumesRW.add(bind);
      }
    }
    return new VolumesRW(volumesRW.toArray(new VolumeRW[volumesRW.size()]));
  }
}

代码示例来源:origin: swagger-api/swagger-core

@Override
  public int compare(JsonNode o1, JsonNode o2) {
    if (o1.equals(o2)) {
      return 0;
    }
    if ((o1 instanceof NumericNode) && (o2 instanceof NumericNode)) {
      double d1 = ((NumericNode) o1).asDouble();
      double d2 = ((NumericNode) o2).asDouble();
      return Double.compare(d1, d2);
    }
    int comp = o1.asText().compareTo(o2.asText());
    if (comp == 0) {
      return Integer.compare(o1.hashCode(), o2.hashCode());
    }
    return comp;
  }
}

相关文章