Debian Codegraph @

src/jakarta/json/JsonBuilderFactory.java

raw symbols SCIP
1 /*
2 * Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved.
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0, which is available at
6 * http://www.eclipse.org/legal/epl-2.0.
7 *
8 * This Source Code may also be made available under the following Secondary
9 * Licenses when the conditions for such availability set forth in the
10 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11 * version 2 with the GNU Classpath Exception, which is available at
12 * https://www.gnu.org/software/classpath/license.html.
13 *
14 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15 */
16
17 package jakarta.json;
18
19 import java.util.Collection;
20 import java.util.Map;
21
22 /**
23 * Factory to create {@link JsonObjectBuilder} and {@link JsonArrayBuilder}
24 * instances. If a factory instance is configured with some configuration,
25 * that would be used to configure the created builder instances.
26 *
27 * <p>
28 * {@code JsonObjectBuilder} and {@code JsonArrayBuilder} can also be created
29 * using {@link Json}'s methods. If multiple builder instances are created,
30 * then creating them using a builder factory is preferred.
31 *
32 * <p>
33 * <b>For example:</b>
34 * <pre>
35 * <code>
36 * JsonBuilderFactory factory = Json.createBuilderFactory(...);
37 * JsonArray value = factory.createArrayBuilder()
38 * .add(factory.createObjectBuilder()
39 * .add("type", "home")
40 * .add("number", "212 555-1234"))
41 * .add(factory.createObjectBuilder()
42 * .add("type", "fax")
43 * .add("number", "646 555-4567"))
44 * .build();
45 * </code>
46 * </pre>
47 *
48 * <p> All the methods in this class are safe for use by multiple concurrent
49 * threads.
50 */
51 public interface JsonBuilderFactory {
52
53 /**
54 * Creates a {@code JsonObjectBuilder} instance that is used to build
55 * {@link JsonObject}.
56 *
57 * @return a JSON object builder
58 */
59 JsonObjectBuilder createObjectBuilder();
60
61 /**
62 * Creates a {@code JsonObjectBuilder} instance, initialized with an object.
63 *
64 * @param object the initial object in the builder
65 * @return a JSON object builder
66 * @throws NullPointerException if specified object is {@code null}
67 *
68 * @since 1.1
69 */
70 default JsonObjectBuilder createObjectBuilder(JsonObject object) {
71 throw new UnsupportedOperationException();
72 }
73
74 /**
75 * Creates a {@code JsonObjectBuilder} instance, initialized with the specified object.
76 *
77 * @param object the initial object in the builder
78 * @return a JSON object builder
79 * @throws NullPointerException if specified object is {@code null}
80 *
81 * @since 1.1
82 */
83 default JsonObjectBuilder createObjectBuilder(Map<String, Object> object) {
84 throw new UnsupportedOperationException();
85 }
86
87 /**
88 * Creates a {@code JsonArrayBuilder} instance that is used to build
89 * {@link JsonArray}
90 *
91 * @return a JSON array builder
92 */
93 JsonArrayBuilder createArrayBuilder();
94
95 /**
96 * Creates a {@code JsonArrayBuilder} instance, initialized with an array.
97 *
98 * @param array the initial array in the builder
99 * @return a JSON array builder
100 * @throws NullPointerException if specified array is {@code null}
101 *
102 * @since 1.1
103 */
104 default JsonArrayBuilder createArrayBuilder(JsonArray array) {
105 throw new UnsupportedOperationException();
106 }
107
108 /**
109 * Creates a {@code JsonArrayBuilder} instance,
110 * initialized with the content of specified collection.
111 *
112 * @param collection the initial data for the builder
113 * @return a JSON array builder
114 * @throws NullPointerException if specified collection is {@code null}
115 *
116 * @since 1.1
117 */
118 default JsonArrayBuilder createArrayBuilder(Collection<?> collection) {
119 throw new UnsupportedOperationException();
120 }
121
122 /**
123 * Returns read-only map of supported provider specific configuration
124 * properties that are used to configure the created JSON builders.
125 * If there are any specified configuration properties that are not
126 * supported by the provider, they won't be part of the returned map.
127 *
128 * @return a map of supported provider specific properties that are used
129 * to configure the builders. The map be empty but not null.
130 */
131 Map<String, ?> getConfigInUse();
132
133 }