Class JsonNumber
- All Implemented Interfaces:
JsonSerializable<JsonElement>
-
Constructor Summary
ConstructorsConstructorDescriptionJsonNumber(Number value) Creates a JsonNumber representing the specified number. -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonNumberfromJson(JsonReader jsonReader) Deserializes a JSON number from a JsonReader.getValue()Returns the Number value from a JsonNumber object.booleanisNumber()Whether the JsonElement is a JsonNumber.toJson(JsonWriter jsonWriter) Writes the object to the passedJsonWriter.Convenience method for writing theJsonSerializableto a JSON string.Methods inherited from class com.azure.json.models.JsonElement
asArray, asBoolean, asNull, asNumber, asObject, asString, isArray, isBoolean, isNull, isObject, isStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.azure.json.JsonSerializable
toJson, toJson, toJsonBytes
-
Constructor Details
-
JsonNumber
Creates a JsonNumber representing the specified number.- Parameters:
value- The number value the JsonNumber will represent.- Throws:
NullPointerException- Ifvalueis null.
-
-
Method Details
-
getValue
Returns the Number value from a JsonNumber object.The value returned by this method will never be null.
- Returns:
- The Number value.
-
isNumber
public boolean isNumber()Whether the JsonElement is a JsonNumber.- Overrides:
isNumberin classJsonElement- Returns:
- boolean of whether this JsonElement object is of type JsonNumber.
-
toJson
Description copied from interface:JsonSerializableWrites the object to the passedJsonWriter.The contract for writing JSON to
JsonWriteris that the object being written will handle opening and closing its own JSON object. So, for objects calling out to otherJsonSerializableobjects for serialization, they'll write the field name only then pass theJsonWriterto the otherJsonSerializableobject. This way objects writing JSON will be self-encapsulated for writing properly formatted JSON.- Parameters:
jsonWriter- Where the object's JSON will be written.- Returns:
- The
JsonWriterwhere the JSON was written. - Throws:
IOException- If the object fails to be written to thejsonWriter.
-
fromJson
Deserializes a JSON number from a JsonReader.If the JsonReader's current token is null, it is assumed the JsonReader hasn't begun reading and
JsonReader.nextToken()will be called to begin reading.After ensuring the JsonReader has begun reading, if the current token is not
JsonToken.NUMBER, anIllegalStateExceptionwill be thrown. Otherwise, a JSON number representing the numeric value will be created and returned.For integer numbers, this method will return the smallest number type that can represent the number. Where
Integeris preferred overLongandLongis preferred overBigInteger.For floating point numbers,
Doublewill be preferred butBigDecimalwill be used if the number is too large to fit in aDouble.If the string is one of the special floating point representations (
NaN,Infinity, etc), then the value will be represented usingDouble.- Parameters:
jsonReader- The JsonReader to deserialize from.- Returns:
- The deserialized JSON number.
- Throws:
IOException- If an error occurs while deserializing the JSON number.IllegalStateException- If the current token is notJsonToken.NUMBER.
-
toJsonString
Description copied from interface:JsonSerializableConvenience method for writing theJsonSerializableto a JSON string.- Returns:
- The JSON string representing the object.
- Throws:
IOException- If the object fails to be written as a JSON string.
-