Package jakarta.json.spi
Class JsonProvider
- java.lang.Object
-
- jakarta.json.spi.JsonProvider
-
public abstract class JsonProvider extends Object
Service provider for JSON processing objects.All the methods in this class are safe for use by multiple concurrent threads.
- See Also:
ServiceLoader
-
-
Field Summary
Fields Modifier and Type Field Description static String
JSONP_PROVIDER_FACTORY
The name of the property that contains the name of the class capable of creating new JsonProvider objects.
-
Constructor Summary
Constructors Modifier Constructor Description protected
JsonProvider()
Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract JsonArrayBuilder
createArrayBuilder()
Creates a JSON array builder.JsonArrayBuilder
createArrayBuilder(JsonArray array)
Creates a JSON array builder, initialized with the specified array.JsonArrayBuilder
createArrayBuilder(Collection<?> collection)
Creates a JSON array builder, initialized with the content of specifiedcollection
.abstract JsonBuilderFactory
createBuilderFactory(Map<String,?> config)
Creates a builder factory for creatingJsonArrayBuilder
andJsonObjectBuilder
objects.JsonPatch
createDiff(JsonStructure source, JsonStructure target)
Generates a JSON Patch (RFC 6902) from the source and targetJsonStructure
.abstract JsonGenerator
createGenerator(OutputStream out)
Creates a JSON generator for writing JSON text to a byte stream.abstract JsonGenerator
createGenerator(Writer writer)
Creates a JSON generator for writing JSON text to a character stream.abstract JsonGeneratorFactory
createGeneratorFactory(Map<String,?> config)
Creates a generator factory for creatingJsonGenerator
instances.JsonMergePatch
createMergeDiff(JsonValue source, JsonValue target)
Generates a JSON Merge Patch (RFC 7396) from the source and targetJsonValue
s which when applied to thesource
, yields thetarget
.JsonMergePatch
createMergePatch(JsonValue patch)
Creates JSON Merge Patch (RFC 7396) from specifiedJsonValue
.abstract JsonObjectBuilder
createObjectBuilder()
Creates a JSON object builder.JsonObjectBuilder
createObjectBuilder(JsonObject object)
Creates a JSON object builder, initialized with the specified object.JsonObjectBuilder
createObjectBuilder(Map<String,?> map)
Creates a JSON object builder, initialized with the data from specifiedmap
.abstract JsonParser
createParser(InputStream in)
Creates a JSON parser from the specified byte stream.abstract JsonParser
createParser(Reader reader)
Creates a JSON parser from a character stream.abstract JsonParserFactory
createParserFactory(Map<String,?> config)
Creates a parser factory for creatingJsonParser
instances.JsonPatch
createPatch(JsonArray array)
Creates a JSON Patch (RFC 6902) from the specified operations.JsonPatchBuilder
createPatchBuilder()
Creates a JSON Patch builder (RFC 6902).JsonPatchBuilder
createPatchBuilder(JsonArray array)
Creates a JSON Patch builder (RFC 6902), initialized with the specified operations.JsonPointer
createPointer(String jsonPointer)
Creates JSON Pointer (RFC 6901) from givenjsonPointer
string.abstract JsonReader
createReader(InputStream in)
Creates a JSON reader from a byte stream.abstract JsonReader
createReader(Reader reader)
Creates a JSON reader from a character stream.abstract JsonReaderFactory
createReaderFactory(Map<String,?> config)
Creates a reader factory for creatingJsonReader
objects.JsonNumber
createValue(double value)
Creates a JsonNumber.JsonNumber
createValue(int value)
Creates a JsonNumber.JsonNumber
createValue(long value)
Creates a JsonNumber.JsonNumber
createValue(Number number)
Creates a JsonNumber.JsonString
createValue(String value)
Creates a JsonString.JsonNumber
createValue(BigDecimal value)
Creates a JsonNumber.JsonNumber
createValue(BigInteger value)
Creates a JsonNumber.abstract JsonWriter
createWriter(OutputStream out)
abstract JsonWriter
createWriter(Writer writer)
abstract JsonWriterFactory
createWriterFactory(Map<String,?> config)
Creates a writer factory for creatingJsonWriter
objects.static JsonProvider
provider()
Creates a JSON provider object.
-
-
-
Field Detail
-
JSONP_PROVIDER_FACTORY
public static final String JSONP_PROVIDER_FACTORY
The name of the property that contains the name of the class capable of creating new JsonProvider objects.- See Also:
- Constant Field Values
-
-
Method Detail
-
provider
public static JsonProvider provider()
Creates a JSON provider object. Implementation discovery consists of following steps:- If the system property "jakarta.json.provider" exists, then its value is assumed to be the provider factory class. This phase of the look up enables per-JVM override of the JsonProvider implementation.
- The provider is loaded using the
ServiceLoader.load(Class)
method. - If all the steps above fail, then the rest of the look up is unspecified. That said, the recommended behavior is to simply look for some hard-coded platform default Jakarta JSON Processing implementation. This phase of the look up is so that a platform can have its own Jakarta JSON Processing implementation as the last resort.
- Returns:
- a JSON provider
- See Also:
ServiceLoader
-
createParser
public abstract JsonParser createParser(Reader reader)
Creates a JSON parser from a character stream.- Parameters:
reader
- i/o reader from which JSON is to be read- Returns:
- a JSON parser
-
createParser
public abstract JsonParser createParser(InputStream in)
Creates a JSON parser from the specified byte stream. The character encoding of the stream is determined as defined in RFC 7159 .- Parameters:
in
- i/o stream from which JSON is to be read- Returns:
- a JSON parser
- Throws:
JsonException
- if encoding cannot be determined or i/o error (IOException would be cause of JsonException)
-
createParserFactory
public abstract JsonParserFactory createParserFactory(Map<String,?> config)
Creates a parser factory for creatingJsonParser
instances. The factory is configured with the specified map of provider specific configuration properties. Provider implementations should ignore any unsupported configuration properties specified in the map.- Parameters:
config
- a map of provider specific properties to configure the JSON parsers. The map may be empty or null- Returns:
- a JSON parser factory
-
createGenerator
public abstract JsonGenerator createGenerator(Writer writer)
Creates a JSON generator for writing JSON text to a character stream.- Parameters:
writer
- a i/o writer to which JSON is written- Returns:
- a JSON generator
-
createGenerator
public abstract JsonGenerator createGenerator(OutputStream out)
Creates a JSON generator for writing JSON text to a byte stream.- Parameters:
out
- i/o stream to which JSON is written- Returns:
- a JSON generator
-
createGeneratorFactory
public abstract JsonGeneratorFactory createGeneratorFactory(Map<String,?> config)
Creates a generator factory for creatingJsonGenerator
instances. The factory is configured with the specified map of provider specific configuration properties. Provider implementations should ignore any unsupported configuration properties specified in the map.- Parameters:
config
- a map of provider specific properties to configure the JSON generators. The map may be empty or null- Returns:
- a JSON generator factory
-
createReader
public abstract JsonReader createReader(Reader reader)
Creates a JSON reader from a character stream.- Parameters:
reader
- a reader from which JSON is to be read- Returns:
- a JSON reader
-
createReader
public abstract JsonReader createReader(InputStream in)
Creates a JSON reader from a byte stream. The character encoding of the stream is determined as described in RFC 7159.- Parameters:
in
- a byte stream from which JSON is to be read- Returns:
- a JSON reader
-
createWriter
public abstract JsonWriter createWriter(Writer writer)
- Parameters:
writer
- to which JSON object or array is written- Returns:
- a JSON writer
-
createWriter
public abstract JsonWriter createWriter(OutputStream out)
Creates a JSON writer to write a JSONobject
orarray
structure to the specified byte stream. Characters written to the stream are encoded into bytes using UTF-8 encoding.- Parameters:
out
- to which JSON object or array is written- Returns:
- a JSON writer
-
createWriterFactory
public abstract JsonWriterFactory createWriterFactory(Map<String,?> config)
Creates a writer factory for creatingJsonWriter
objects. The factory is configured with the specified map of provider specific configuration properties. Provider implementations should ignore any unsupported configuration properties specified in the map.- Parameters:
config
- a map of provider specific properties to configure the JSON writers. The map may be empty or null- Returns:
- a JSON writer factory
-
createReaderFactory
public abstract JsonReaderFactory createReaderFactory(Map<String,?> config)
Creates a reader factory for creatingJsonReader
objects. The factory is configured with the specified map of provider specific configuration properties. Provider implementations should ignore any unsupported configuration properties specified in the map.- Parameters:
config
- a map of provider specific properties to configure the JSON readers. The map may be empty or null- Returns:
- a JSON reader factory
-
createObjectBuilder
public abstract JsonObjectBuilder createObjectBuilder()
Creates a JSON object builder.- Returns:
- a JSON object builder
-
createObjectBuilder
public JsonObjectBuilder createObjectBuilder(JsonObject object)
Creates a JSON object builder, initialized with the specified object.- Parameters:
object
- the initial JSON object in the builder- Returns:
- a JSON object builder
- Since:
- 1.1
-
createObjectBuilder
public JsonObjectBuilder createObjectBuilder(Map<String,?> map)
Creates a JSON object builder, initialized with the data from specifiedmap
. If the @{code map} containsOptional
s then resulting JSON object builder contains the key from themap
only if theOptional
is not empty.- Parameters:
map
- the initial object in the builder- Returns:
- a JSON object builder
- Throws:
IllegalArgumentException
- if the value from themap
cannot be converted to the correspondingJsonValue
- Since:
- 1.1
-
createArrayBuilder
public abstract JsonArrayBuilder createArrayBuilder()
Creates a JSON array builder.- Returns:
- a JSON array builder
-
createArrayBuilder
public JsonArrayBuilder createArrayBuilder(JsonArray array)
Creates a JSON array builder, initialized with the specified array.- Parameters:
array
- the initial JSON array in the builder- Returns:
- a JSON array builder
- Since:
- 1.1
-
createPointer
public JsonPointer createPointer(String jsonPointer)
Creates JSON Pointer (RFC 6901) from givenjsonPointer
string.- An empty
jsonPointer
string defines a reference to the target itself. - If the
jsonPointer
string is non-empty, it must be a sequence of '/
' prefixed tokens.
- Parameters:
jsonPointer
- the JSON Pointer string- Returns:
- a JSON Pointer
- Throws:
NullPointerException
- ifjsonPointer
isnull
JsonException
- ifjsonPointer
is not a valid JSON Pointer- Since:
- 1.1
- An empty
-
createPatchBuilder
public JsonPatchBuilder createPatchBuilder()
Creates a JSON Patch builder (RFC 6902).- Returns:
- a JSON Patch builder
- Since:
- 1.1
-
createPatchBuilder
public JsonPatchBuilder createPatchBuilder(JsonArray array)
Creates a JSON Patch builder (RFC 6902), initialized with the specified operations.- Parameters:
array
- the initial patch operations- Returns:
- a JSON Patch builder
- Since:
- 1.1
-
createPatch
public JsonPatch createPatch(JsonArray array)
Creates a JSON Patch (RFC 6902) from the specified operations.- Parameters:
array
- patch operations- Returns:
- a JSON Patch
- Since:
- 1.1
-
createDiff
public JsonPatch createDiff(JsonStructure source, JsonStructure target)
Generates a JSON Patch (RFC 6902) from the source and targetJsonStructure
. The generated JSON Patch need not be unique.- Parameters:
source
- the sourcetarget
- the target, must be the same type as the source- Returns:
- a JSON Patch which when applied to the source, yields the target
- Since:
- 1.1
-
createMergePatch
public JsonMergePatch createMergePatch(JsonValue patch)
Creates JSON Merge Patch (RFC 7396) from specifiedJsonValue
.- Parameters:
patch
- the patch- Returns:
- a JSON Merge Patch
- Since:
- 1.1
-
createMergeDiff
public JsonMergePatch createMergeDiff(JsonValue source, JsonValue target)
Generates a JSON Merge Patch (RFC 7396) from the source and targetJsonValue
s which when applied to thesource
, yields thetarget
.- Parameters:
source
- the sourcetarget
- the target- Returns:
- a JSON Merge Patch
- Since:
- 1.1
-
createArrayBuilder
public JsonArrayBuilder createArrayBuilder(Collection<?> collection)
Creates a JSON array builder, initialized with the content of specifiedcollection
. If the @{code collection} containsOptional
s then resulting JSON array builder contains the value from thecollection
only if theOptional
is not empty.- Parameters:
collection
- the initial data for the builder- Returns:
- a JSON array builder
- Throws:
IllegalArgumentException
- if the value from thecollection
cannot be converted to the correspondingJsonValue
- Since:
- 1.1
-
createBuilderFactory
public abstract JsonBuilderFactory createBuilderFactory(Map<String,?> config)
Creates a builder factory for creatingJsonArrayBuilder
andJsonObjectBuilder
objects. The factory is configured with the specified map of provider specific configuration properties. Provider implementations should ignore any unsupported configuration properties specified in the map.- Parameters:
config
- a map of provider specific properties to configure the JSON builders. The map may be empty or null- Returns:
- a JSON builder factory
-
createValue
public JsonString createValue(String value)
Creates a JsonString.- Parameters:
value
- a JSON string- Returns:
- the JsonString for the string
- Since:
- 1.1
-
createValue
public JsonNumber createValue(int value)
Creates a JsonNumber.- Parameters:
value
- a JSON number- Returns:
- the JsonNumber for the number
- Since:
- 1.1
-
createValue
public JsonNumber createValue(long value)
Creates a JsonNumber.- Parameters:
value
- a JSON number- Returns:
- the JsonNumber for the number
- Since:
- 1.1
-
createValue
public JsonNumber createValue(double value)
Creates a JsonNumber.- Parameters:
value
- a JSON number- Returns:
- the JsonNumber for the number
- Since:
- 1.1
-
createValue
public JsonNumber createValue(BigDecimal value)
Creates a JsonNumber.- Parameters:
value
- a JSON number- Returns:
- the JsonNumber for the number
- Since:
- 1.1
-
createValue
public JsonNumber createValue(BigInteger value)
Creates a JsonNumber.- Parameters:
value
- a JSON number- Returns:
- the JsonNumber for the number
- Since:
- 1.1
-
createValue
public JsonNumber createValue(Number number)
Creates a JsonNumber. When it is not implemented it checks the type and delegates to an existing method that already handles that type. It throws UnsupportedOperationException in case the type is not known.- Parameters:
number
- a JSON number- Returns:
- the JsonNumber for the number
- Since:
- 2.1
-
-