Class JsonNumber

java.lang.Object
io.helidon.json.JsonValue
io.helidon.json.JsonNumber

public final class JsonNumber extends JsonValue
Represents a JSON number value. Equality follows BigDecimal.equals(Object), including its scale-sensitive semantics.
  • Method Details

    • create

      public static JsonNumber create(BigDecimal bigDecimalValue)
      Create a JsonNumber from a BigDecimal value.
      Parameters:
      bigDecimalValue - the BigDecimal value
      Returns:
      a new JsonNumber
    • create

      public static JsonNumber create(double doubleValue)
      Create a JsonNumber from a double value.
      Parameters:
      doubleValue - the double value
      Returns:
      a new JsonNumber
    • create

      public static JsonNumber create(long longValue)
      Create a JsonNumber from a long value.
      Parameters:
      longValue - the long value
      Returns:
      a new JsonNumber
    • doubleValue

      public double doubleValue()
      Return the double value of this JsonNumber. This conversion may lose precision or return an infinity if the magnitude is too large.
      Returns:
      the double value
      See Also:
    • byteValue

      public byte byteValue()
      Return the byte value of this JsonNumber. Any fractional part is discarded. If the resulting integer does not fit, only the low-order 8 bits are returned, so the result may have the opposite sign.
      Returns:
      the byte value
      See Also:
    • shortValue

      public short shortValue()
      Return the short value of this JsonNumber. Any fractional part is discarded. If the resulting integer does not fit, only the low-order 16 bits are returned, so the result may have the opposite sign.
      Returns:
      the short value
      See Also:
    • intValue

      public int intValue()
      Return the int value of this JsonNumber. Any fractional part is discarded. If the resulting integer does not fit, only the low-order 32 bits are returned, so the result may have the opposite sign.
      Returns:
      the int value
      See Also:
    • longValue

      public long longValue()
      Return the long value of this JsonNumber. Any fractional part is discarded. If the resulting integer does not fit, only the low-order 64 bits are returned, so the result may have the opposite sign.
      Returns:
      the long value
      See Also:
    • floatValue

      public float floatValue()
      Return the float value of this JsonNumber. This conversion may lose precision or return an infinity if the magnitude is too large.
      Returns:
      the float value
      See Also:
    • bigIntegerValue

      public BigInteger bigIntegerValue()
      Return the BigInteger value of this JsonNumber. Any fractional part is discarded.

      For a nonzero value with a negative scale, a conversion may introduce at most 4,096 trailing decimal digits. Numbers originating from the same parsed JSON document also share a cumulative budget of 65,536 such digits; every invocation consumes that document budget. Programmatically created numbers have only the per-conversion limit.

      Returns:
      the BigInteger value
      Throws:
      JsonException - if the conversion exceeds the per-value or parsed-document expansion budget
      See Also:
    • bigDecimalValue

      public BigDecimal bigDecimalValue()
      Return the BigDecimal value of this JsonNumber.
      Returns:
      the BigDecimal value
    • type

      public JsonValueType type()
      Description copied from class: JsonValue
      Return the type of this JSON value.
      Specified by:
      type in class JsonValue
      Returns:
      the JsonValueType of this value
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toJson

      public void toJson(JsonGenerator generator)
      Description copied from class: JsonValue
      Write this JSON value to the provided generator.
      Specified by:
      toJson in class JsonValue
      Parameters:
      generator - the generator to write to