|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.json.JsonBuilder
public class JsonBuilder
Builds a JSON object or array from
scratch. It uses builder pattern to build these object models and the
builder methods can be chained.
For example, for the following JSON
a JsonObject instance can be built using:
{
"firstName": "John", "lastName": "Smith", "age": 25,
"address" : {
"streetAddress", "21 2nd Street",
"city", "New York",
"state", "NY",
"postalCode", "10021"
},
"phoneNumber": [
{ "type": "home", "number": "212 555-1234" },
{ "type": "fax", "number": "646 555-4567" }
]
}
JsonObject value = new JsonBuilder()
.beginObject()
.add("firstName", "John")
.add("lastName", "Smith")
.add("age", 25)
.beginObject("address")
.add("streetAddress", "21 2nd Street")
.add("city", "New York")
.add("state", "NY")
.add("postalCode", "10021")
.endObject()
.beginArray("phoneNumber")
.beginObject()
.add("type", "home")
.add("number", "212 555-1234")
.endObject()
.beginObject()
.add("type", "home")
.add("number", "646 555-4567")
.endObject()
.endArray()
.endObject()
.build();
| Nested Class Summary | |
|---|---|
static interface |
JsonBuilder.JsonBuildable<T extends JsonStructure>
Build task that gives the result of the build process |
| Constructor Summary | |
|---|---|
JsonBuilder()
|
|
| Method Summary | |
|---|---|
JsonArrayBuilder<JsonBuilder.JsonBuildable<JsonArray>> |
beginArray()
Start building a JSON array |
JsonObjectBuilder<JsonBuilder.JsonBuildable<JsonObject>> |
beginObject()
Start building a JSON object |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public JsonBuilder()
| Method Detail |
|---|
public JsonObjectBuilder<JsonBuilder.JsonBuildable<JsonObject>> beginObject()
public JsonArrayBuilder<JsonBuilder.JsonBuildable<JsonArray>> beginArray()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||