Class JsonObject
- All Implemented Interfaces:
JsonValue
Names are unique and compared exactly, with no case folding or Unicode normalization. Two objects are equal when they have the same names with equal values, whatever the order of their members.
Building. builder() adds one member per put call, and a name that is already
present throws IllegalArgumentException instead of replacing the earlier value. fromMembers(Map)
takes a complete map.
Member lookups. find(String) returns an empty Optional only when a member is
absent. A present member retains its JsonValue type, including JsonNull; callers can inspect that
type to distinguish an absent member from a malformed one.
- Since:
- 1.0.0
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilds aJsonObjectone member at a time, keeping the order in which members are added. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull JsonObject.Builderbuilder()Returns a new builder, which adds one member perputcall.static @NonNull JsonObjectReturns the empty JSON object.booleanReturns the value of the member namedname.static @NonNull JsonObjectReturns a JSON object holding a snapshot ofmembers, in the map's iteration order.Returns this object's members, in the order they were added.inthashCode()toJson()Serializes this value as compact JSON text: no insignificant whitespace, members in insertion order, and numbers in the canonical form ofBigDecimal.toString()(1e2becomes1E+2).toString()
-
Method Details
-
emptyInstance
Returns the empty JSON object.- Returns:
- the shared empty object
- Since:
- 1.0.0
-
builder
Returns a new builder, which adds one member perputcall.- Returns:
- a builder with no members
- Since:
- 1.0.0
-
fromMembers
public static @NonNull JsonObject fromMembers(@NonNull Map<@NonNull String, ? extends @NonNull JsonValue> members) Returns a JSON object holding a snapshot ofmembers, in the map's iteration order.- Parameters:
members- the members; later changes to the map do not affect the object- Returns:
- the JSON object
- Throws:
NullPointerException- ifmembers, or any name or value in it, isnullIllegalArgumentException- if a name contains an unpaired surrogate, the map holds two equal names (as an identity-based map can), or the object would nest more than 64 deep- Since:
- 1.0.0
-
getMembers
-
find
Returns the value of the member namedname.- Parameters:
name- the member name, compared exactly- Returns:
- the value, which may be
JsonNull, or empty if there is no such member - Throws:
NullPointerException- ifnameisnull- Since:
- 1.0.0
-
toJson
Description copied from interface:JsonValueSerializes this value as compact JSON text: no insignificant whitespace, members in insertion order, and numbers in the canonical form ofBigDecimal.toString()(1e2becomes1E+2).Strings escape only what JSON requires: the quotation mark, the reverse solidus and the control characters U+0000 to U+001F, using the two-character escapes where they exist. Every other character, U+2028 and U+2029 included, is written as itself.
Unlike
toString(), the result contains every string and number this value holds. It is not the text a value was parsed from, so never verify a signature over it. -
equals
-
hashCode
-
toString
-