Package com.unboundid.util.json
Class JSONField
- java.lang.Object
-
- com.unboundid.util.json.JSONField
-
- All Implemented Interfaces:
java.io.Serializable
@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class JSONField extends java.lang.Object implements java.io.Serializable
This class provides a simple data structure that represents a field in a JSON object, containing a name and a value. This is primarily intended as a convenience when programmatically constructing JSON objects.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description JSONField(java.lang.String name, boolean value)
Creates a new JSON field with the specified name and aJSONBoolean
value.JSONField(java.lang.String name, double value)
Creates a new JSON field with the specified name and aJSONNumber
value.JSONField(java.lang.String name, long value)
Creates a new JSON field with the specified name and aJSONNumber
value.JSONField(java.lang.String name, JSONValue value)
Creates a new JSON field with the specified name and value.JSONField(java.lang.String name, java.lang.String value)
Creates a new JSON field with the specified name and aJSONString
value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
Indicates whether the provided object is considered equal to this JSON field.java.lang.String
getName()
Retrieves the name for this field.JSONValue
getValue()
Retrieves the value for this field.int
hashCode()
Retrieves a hash code for this JSON field.java.lang.String
toString()
Retrieves a string representation of this field.void
toString(java.lang.StringBuilder buffer)
Appends a string representation of this field to the provided buffer.
-
-
-
Constructor Detail
-
JSONField
public JSONField(@NotNull java.lang.String name, @NotNull JSONValue value)
Creates a new JSON field with the specified name and value.- Parameters:
name
- The name for this field. It must not benull
.value
- The value for this field. It must not benull
(although it may be aJSONNull
instance).
-
JSONField
public JSONField(@NotNull java.lang.String name, boolean value)
Creates a new JSON field with the specified name and aJSONBoolean
value.- Parameters:
name
- The name for this field. It must not benull
.value
- The value for this field. It must not benull
.
-
JSONField
public JSONField(@NotNull java.lang.String name, long value)
Creates a new JSON field with the specified name and aJSONNumber
value.- Parameters:
name
- The name for this field. It must not benull
.value
- The value for this field. It must not benull
.
-
JSONField
public JSONField(@NotNull java.lang.String name, double value)
Creates a new JSON field with the specified name and aJSONNumber
value.- Parameters:
name
- The name for this field. It must not benull
.value
- The value for this field. It must not benull
.
-
JSONField
public JSONField(@NotNull java.lang.String name, @NotNull java.lang.String value)
Creates a new JSON field with the specified name and aJSONString
value.- Parameters:
name
- The name for this field. It must not benull
.value
- The value for this field. It must not benull
.
-
-
Method Detail
-
getName
@NotNull public java.lang.String getName()
Retrieves the name for this field.- Returns:
- The name for this field.
-
getValue
@NotNull public JSONValue getValue()
Retrieves the value for this field.- Returns:
- The value for this field.
-
hashCode
public int hashCode()
Retrieves a hash code for this JSON field.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- A hash code for this JSON field.
-
equals
public boolean equals(@Nullable java.lang.Object o)
Indicates whether the provided object is considered equal to this JSON field.- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- The object for which to make the determination.- Returns:
true
if the provided object is a JSON field with the same name and an equivalent value, orfalse
if not.
-
toString
@NotNull public java.lang.String toString()
Retrieves a string representation of this field.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A string representation of this field.
-
-