@Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null || getClass() != obj.getClass()) {
      return false;
    }
    JsonPrimitive other = (JsonPrimitive) obj;
    if (value == null) {
      return other.value == null;
    }
    if (isIntegral(this) && isIntegral(other)) {
      return (this.value instanceof BigInteger || other.value instanceof BigInteger)
          ? this.getAsBigInteger().equals(other.getAsBigInteger())
          : this.getAsNumber().longValue() == other.getAsNumber().longValue();
    }
    if (value instanceof Number && other.value instanceof Number) {
      if (value instanceof BigDecimal && other.value instanceof BigDecimal) {
        // Uses compareTo to ignore scale of values, e.g. `0` and `0.00` should be considered equal
        return this.getAsBigDecimal().compareTo(other.getAsBigDecimal()) == 0;
      }

      double thisAsDouble = this.getAsDouble();
      double otherAsDouble = other.getAsDouble();
      // Don't use Double.compare(double, double) because that considers -0.0 and +0.0 not equal
      return (thisAsDouble == otherAsDouble)
          || (Double.isNaN(thisAsDouble) && Double.isNaN(otherAsDouble));
    }
    return value.equals(other.value);
  }
@Test
  public void testEqualsDoubleNaNAndBigDecimal() {
    assertThat(new JsonPrimitive(Double.NaN).equals(new JsonPrimitive(new BigDecimal("1.0"))))
        .isFalse();
  }