public class JsonUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ACCEPT_HEADER
An HTTP Accept header that prefers JSONLD.
|
Constructor and Description |
---|
JsonUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
fromInputStream(java.io.InputStream input)
Parses a JSON-LD document from the given
InputStream to an object
that can be used as input for the JsonLdApi and
JsonLdProcessor methods.Uses UTF-8 as the character encoding when decoding the InputStream. |
static java.lang.Object |
fromInputStream(java.io.InputStream input,
java.lang.String enc)
Parses a JSON-LD document from the given
InputStream to an object
that can be used as input for the JsonLdApi and
JsonLdProcessor methods. |
static java.lang.Object |
fromReader(java.io.Reader reader)
Parses a JSON-LD document from the given
Reader to an object that
can be used as input for the JsonLdApi and
JsonLdProcessor methods. |
static java.lang.Object |
fromString(java.lang.String jsonString)
Parses a JSON-LD document from a string to an object that can be used as
input for the
JsonLdApi and JsonLdProcessor methods. |
static java.lang.Object |
fromURL(java.net.URL url,
CloseableHttpClient httpClient)
Parses a JSON-LD document, from the contents of the JSON resource
resolved from the JsonLdUrl, to an object that can be used as input for
the
JsonLdApi and JsonLdProcessor methods. |
static java.lang.Object |
fromURLJavaNet(java.net.URL url)
Fallback method directly using the
HttpURLConnection
class for cases where servers do not interoperate correctly with Apache
HTTPClient. |
static CloseableHttpClient |
getDefaultHttpClient() |
static java.lang.String |
toPrettyString(java.lang.Object jsonObject)
Writes the given JSON-LD Object out to a String, using indentation and
new lines to improve readability.
|
static java.lang.String |
toString(java.lang.Object jsonObject)
Writes the given JSON-LD Object out to a String.
|
static void |
write(java.io.Writer writer,
java.lang.Object jsonObject)
Writes the given JSON-LD Object out to the given Writer.
|
static void |
writePrettyPrint(java.io.Writer writer,
java.lang.Object jsonObject)
Writes the given JSON-LD Object out to the given Writer, using
indentation and new lines to improve readability.
|
public static final java.lang.String ACCEPT_HEADER
public static java.lang.Object fromInputStream(java.io.InputStream input) throws java.io.IOException
InputStream
to an object
that can be used as input for the JsonLdApi
and
JsonLdProcessor
methods.input
- The JSON-LD document in an InputStream.JsonParseException
- If there was a JSON related error during parsing.java.io.IOException
- If there was an IO error during parsing.public static java.lang.Object fromInputStream(java.io.InputStream input, java.lang.String enc) throws java.io.IOException
InputStream
to an object
that can be used as input for the JsonLdApi
and
JsonLdProcessor
methods.input
- The JSON-LD document in an InputStream.enc
- The character encoding to use when interpreting the characters
in the InputStream.JsonParseException
- If there was a JSON related error during parsing.java.io.IOException
- If there was an IO error during parsing.public static java.lang.Object fromReader(java.io.Reader reader) throws java.io.IOException
Reader
to an object that
can be used as input for the JsonLdApi
and
JsonLdProcessor
methods.reader
- The JSON-LD document in a Reader.JsonParseException
- If there was a JSON related error during parsing.java.io.IOException
- If there was an IO error during parsing.public static java.lang.Object fromString(java.lang.String jsonString) throws JsonParseException, java.io.IOException
JsonLdApi
and JsonLdProcessor
methods.jsonString
- The JSON-LD document as a string.JsonParseException
- If there was a JSON related error during parsing.java.io.IOException
- If there was an IO error during parsing.public static java.lang.String toPrettyString(java.lang.Object jsonObject) throws JsonGenerationException, java.io.IOException
jsonObject
- The JSON-LD Object to serialize.JsonGenerationException
- If there is a JSON error during serialization.java.io.IOException
- If there is an IO error during serialization.public static java.lang.String toString(java.lang.Object jsonObject) throws JsonGenerationException, java.io.IOException
jsonObject
- The JSON-LD Object to serialize.JsonGenerationException
- If there is a JSON error during serialization.java.io.IOException
- If there is an IO error during serialization.public static void write(java.io.Writer writer, java.lang.Object jsonObject) throws JsonGenerationException, java.io.IOException
writer
- The writer that is to receive the serialized JSON-LD object.jsonObject
- The JSON-LD Object to serialize.JsonGenerationException
- If there is a JSON error during serialization.java.io.IOException
- If there is an IO error during serialization.public static void writePrettyPrint(java.io.Writer writer, java.lang.Object jsonObject) throws JsonGenerationException, java.io.IOException
writer
- The writer that is to receive the serialized JSON-LD object.jsonObject
- The JSON-LD Object to serialize.JsonGenerationException
- If there is a JSON error during serialization.java.io.IOException
- If there is an IO error during serialization.public static java.lang.Object fromURL(java.net.URL url, CloseableHttpClient httpClient) throws JsonParseException, java.io.IOException
JsonLdApi
and JsonLdProcessor
methods.url
- The JsonLdUrl to resolvehttpClient
- The CloseableHttpClient
to use to resolve the URL.JsonParseException
- If there was a JSON related error during parsing.java.io.IOException
- If there was an IO error during parsing.public static java.lang.Object fromURLJavaNet(java.net.URL url) throws JsonParseException, java.io.IOException
HttpURLConnection
class for cases where servers do not interoperate correctly with Apache
HTTPClient.url
- The URL to access.JsonParseException
- If there was a JSON related error during parsing.java.io.IOException
- If there was an IO error during parsing.public static CloseableHttpClient getDefaultHttpClient()