|
Eclipse Remote Application Platform | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.rap.json.JsonValue org.eclipse.rap.json.JsonObject
public class JsonObject
Represents a JSON object. A JSON object contains a sequence of members, which are pairs of a name
and a JSON value (see JsonValue
). Although JSON objects should be used for unordered
collections, this class stores members in document order.
Members can be added using one of the different add(...)
methods. Accepted values
are either instances of JsonValue
, or strings, primitive numbers, or boolean values.
Members can be accessed by their name using get(String)
. A list of all names can be
obtained from the method names()
.
Note that this class is not thread-safe. If multiple threads access a
JsonObject
instance concurrently, while at least one of these threads modifies the
contents of this object, access to the instance must be synchronized externally. Failure to do so
may lead to an inconsistent state.
This class is not supposed to be extended by clients.
Field Summary |
---|
Fields inherited from class org.eclipse.rap.json.JsonValue |
---|
FALSE, NULL, TRUE |
Constructor Summary | |
---|---|
JsonObject()
Creates a new empty JsonObject. |
|
JsonObject(JsonObject object)
Creates a new JsonObject, initialized with the contents of the specified JSON object. |
Method Summary | |
---|---|
JsonObject |
add(java.lang.String name,
boolean value)
Adds a new member to this object, with the specified name and the JSON representation of the specified boolean value. |
JsonObject |
add(java.lang.String name,
double value)
Adds a new member to this object, with the specified name and the JSON representation of the specified double value. |
JsonObject |
add(java.lang.String name,
float value)
Adds a new member to this object, with the specified name and the JSON representation of the specified float value. |
JsonObject |
add(java.lang.String name,
JsonValue value)
Adds a new member to this object, with the specified name and JSON value. |
JsonObject |
add(java.lang.String name,
long value)
Adds a new member to this object, with the specified name and the JSON representation of the specified long value. |
JsonObject |
add(java.lang.String name,
java.lang.String value)
Adds a new member to this object, with the specified name and the JSON representation of the specified string. |
JsonObject |
asObject()
Returns this JSON value as JsonObject , assuming that this value represents a JSON
object. |
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one according to the contract specified in Object.equals(Object) . |
JsonValue |
get(java.lang.String name)
Returns the value of the member with the specified name in this object. |
int |
hashCode()
|
boolean |
isEmpty()
Returns true if this object contains no members. |
boolean |
isObject()
Detects whether this value represents a JSON object. |
java.util.List<java.lang.String> |
names()
Returns a list of the names in this object in document order. |
static JsonObject |
readFrom(java.io.Reader reader)
Reads a JSON object from the given reader. |
static JsonObject |
readFrom(java.lang.String string)
Reads a JSON object from the given string. |
JsonObject |
remove(java.lang.String name)
Removes a member with the specified name from this object. |
int |
size()
Returns the number of members (i.e. |
static JsonObject |
unmodifiableObject(JsonObject object)
Returns an unmodifiable JsonObject for the specified one. |
protected void |
write(org.eclipse.rap.json.JsonWriter writer)
|
Methods inherited from class org.eclipse.rap.json.JsonValue |
---|
asArray, asBoolean, asDouble, asFloat, asInt, asLong, asString, isArray, isBoolean, isFalse, isNull, isNumber, isString, isTrue, toString, valueOf, valueOf, valueOf, valueOf, valueOf, writeTo |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public JsonObject()
public JsonObject(JsonObject object)
object
- the JSON object to get the initial contents from, must not be null
Method Detail |
---|
public static JsonObject readFrom(java.io.Reader reader) throws java.io.IOException
reader
- the reader to read the JSON object from
java.io.IOException
- if an I/O error occurs in the reader
ParseException
- if the input is not valid JSON
java.lang.UnsupportedOperationException
- if the input does not contain a JSON objectpublic static JsonObject readFrom(java.lang.String string)
string
- the string that contains the JSON object
ParseException
- if the input is not valid JSON
java.lang.UnsupportedOperationException
- if the input does not contain a JSON objectpublic static JsonObject unmodifiableObject(JsonObject object)
The returned JsonObject is backed by the given object and reflect changes that happen to it.
Attempts to modify the returned JsonObject result in an
UnsupportedOperationException
.
object
- the JsonObject for which an unmodifiable JsonObject is to be returned
public JsonObject add(java.lang.String name, long value)
long
value.
This method does not prevent duplicate names. Adding a member with a name that
is already contained in the object will add another member with the same name. In order to
ensure that the names are unique, the method remove( String )
can be called before
calling this method. However, this practice incurs a performance penalty and should only be
used when the calling code can not ensure that same name won't be added more than once.
name
- the name of the member to addvalue
- the value of the member to add
public JsonObject add(java.lang.String name, float value)
float
value.
This method does not prevent duplicate names. Adding a member with a name that
is already contained in the object will add another member with the same name. In order to
ensure that the names are unique, the method remove( String )
can be called before
calling this method. However, this practice incurs a performance penalty and should only be
used when the calling code can not ensure that same name won't be added more than once.
name
- the name of the member to addvalue
- the value of the member to add
public JsonObject add(java.lang.String name, double value)
double
value.
This method does not prevent duplicate names. Adding a member with a name that
is already contained in the object will add another member with the same name. In order to
ensure that the names are unique, the method remove( String )
can be called before
calling this method. However, this practice incurs a performance penalty and should only be
used when the calling code can not ensure that same name won't be added more than once.
name
- the name of the member to addvalue
- the value of the member to add
public JsonObject add(java.lang.String name, boolean value)
boolean
value.
This method does not prevent duplicate names. Adding a member with a name that
is already contained in the object will add another member with the same name. In order to
ensure that the names are unique, the method remove( String )
can be called before
calling this method. However, this practice incurs a performance penalty and should only be
used when the calling code can not ensure that same name won't be added more than once.
name
- the name of the member to addvalue
- the value of the member to add
public JsonObject add(java.lang.String name, java.lang.String value)
This method does not prevent duplicate names. Adding a member with a name that
is already contained in the object will add another member with the same name. In order to
ensure that the names are unique, the method remove( String )
can be called before
calling this method. However, this practice incurs a performance penalty and should only be
used when the calling code can not ensure that same name won't be added more than once.
name
- the name of the member to addvalue
- the value of the member to add
public JsonObject add(java.lang.String name, JsonValue value)
This method does not prevent duplicate names. Adding a member with a name that
is already contained in the object will add another member with the same name. In order to
ensure that the names are unique, the method remove( String )
can be called before
calling this method. However, this practice incurs a performance penalty and should only be
used when the calling code can not ensure that same name won't be added more than once.
name
- the name of the member to addvalue
- the value of the member to add
public JsonObject remove(java.lang.String name)
name
- the name of the member to remove
public JsonValue get(java.lang.String name)
name
- the name of the member whose value is to be returned
null
if there is no
member with that name in this objectpublic int size()
public boolean isEmpty()
true
if this object contains no members.
true
if this object contains no memberspublic java.util.List<java.lang.String> names()
protected void write(org.eclipse.rap.json.JsonWriter writer) throws java.io.IOException
write
in class JsonValue
java.io.IOException
public boolean isObject()
JsonValue
JsonObject
.
isObject
in class JsonValue
true
if this value is an instance of JsonObjectpublic JsonObject asObject()
JsonValue
JsonObject
, assuming that this value represents a JSON
object. If this is not the case, an exception is thrown.
asObject
in class JsonValue
public int hashCode()
hashCode
in class JsonValue
public boolean equals(java.lang.Object obj)
JsonValue
Object.equals(Object)
.
Two JsonValues are considered equal if and only if they represent the same JSON text. As a consequence, two given JsonObjects may be different even though they contain the same set of names with the same values, but in a different order.
equals
in class JsonValue
obj
- the reference object with which to compare
|
Eclipse Remote Application Platform | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright (c) EclipseSource and others 2002, 2013. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0