public class Jsoner extends Object
Modifier and Type | Method and Description |
---|---|
static Object |
deserialize(Reader readableDeserializable)
Deserializes a readable stream according to the RFC 4627 JSON specification.
|
static Object |
deserialize(String deserializable)
A convenience method that assumes a StringReader to deserialize a string.
|
static JsonArray |
deserialize(String deserializable,
JsonArray defaultValue)
A convenience method that assumes a JsonArray must be deserialized.
|
static JsonObject |
deserialize(String deserializable,
JsonObject defaultValue)
A convenience method that assumes a JsonObject must be deserialized.
|
static JsonArray |
deserializeMany(Reader deserializable)
A convenience method that assumes multiple RFC 4627 JSON values (except numbers) have been concatenated together
for deserilization which will be collectively returned in a JsonArray wrapper.
|
static String |
escape(String escapable)
Escapes potentially confusing or important characters in the String provided.
|
static JsonKey |
mintJsonKey(String key,
Object value)
Creates a new JsonKey that wraps the given string and value.
|
static String |
prettyPrint(String printable)
Formats the JSON string to be more easily human readable using tabs for indentation.
|
static String |
prettyPrint(String printable,
int spaces)
Formats the JSON string to be more easily human readable using an arbitrary amount of spaces for indentation.
|
static String |
serialize(Object jsonSerializable)
A convenience method that assumes a StringWriter.
|
static void |
serialize(Object jsonSerializable,
Writer writableDestination)
Serializes values according to the RFC 4627 JSON specification.
|
static void |
serializeCarelessly(Object jsonSerializable,
Writer writableDestination)
Serializes like the first version of this library.
|
static void |
serializeStrictly(Object jsonSerializable,
Writer writableDestination)
Serializes JSON values and only JSON values according to the RFC 4627 JSON specification.
|
public static Object deserialize(Reader readableDeserializable) throws JsonException
readableDeserializable
- representing content to be deserialized as JSON.JsonException
- if an unexpected token is encountered in the deserializable. To recover from a
JsonException: fix the deserializable to no longer have an unexpected token and try again.public static Object deserialize(String deserializable) throws JsonException
deserializable
- representing content to be deserialized as JSON.JsonException
- if an unexpected token is encountered in the deserializable. To recover from a
JsonException: fix the deserializable to no longer have an unexpected token and try again.deserialize(Reader)
,
StringReader
public static JsonArray deserialize(String deserializable, JsonArray defaultValue)
deserializable
- representing content to be deserializable as a JsonArray.defaultValue
- representing what would be returned if deserializable isn't a JsonArray or an IOException,
NullPointerException, or JsonException occurs during deserialization.deserialize(Reader)
public static JsonObject deserialize(String deserializable, JsonObject defaultValue)
deserializable
- representing content to be deserializable as a JsonObject.defaultValue
- representing what would be returned if deserializable isn't a JsonObject or an IOException,
NullPointerException, or JsonException occurs during deserialization.deserialize(Reader)
public static JsonArray deserializeMany(Reader deserializable) throws JsonException
deserializable
- representing concatenated content to be deserialized as JSON in one reader. Its contents
may not contain two numbers concatenated together.JsonException
- if an unexpected token is encountered in the deserializable. To recover from a
JsonException: fix the deserializable to no longer have an unexpected token and try again.public static String escape(String escapable)
escapable
- an unescaped string.public static JsonKey mintJsonKey(String key, Object value)
key
- represents the JsonKey as a String.value
- represents the value the JsonKey uses.public static String prettyPrint(String printable)
printable
- representing a JSON formatted string with out extraneous characters, like one returned from
Jsoner#serialize(Object).public static String prettyPrint(String printable, int spaces)
printable
- representing a JSON formatted string with out extraneous characters, like one returned from
Jsoner#serialize(Object).spaces
- representing the amount of spaces to use for indentation. Must be between 2 and 10.IllegalArgumentException
- if spaces isn't between [2..10].prettyPrint(String)
public static String serialize(Object jsonSerializable)
jsonSerializable
- represents the object that should be serialized as a string in JSON format.IllegalArgumentException
- if the jsonSerializable isn't serializable in JSON.serialize(Object, Writer)
,
StringWriter
public static void serialize(Object jsonSerializable, Writer writableDestination) throws IOException
jsonSerializable
- represents the object that should be serialized in JSON format.writableDestination
- represents where the resulting JSON text is written to.IOException
- if the writableDestination encounters an I/O problem, like being closed while in use.IllegalArgumentException
- if the jsonSerializable isn't serializable in JSON.public static void serializeCarelessly(Object jsonSerializable, Writer writableDestination) throws IOException
jsonSerializable
- represents the object that should be serialized in JSON format.writableDestination
- represents where the resulting JSON text is written to.IOException
- if the writableDestination encounters an I/O problem, like being closed while in use.public static void serializeStrictly(Object jsonSerializable, Writer writableDestination) throws IOException
jsonSerializable
- represents the object that should be serialized in JSON format.writableDestination
- represents where the resulting JSON text is written to.IOException
- if the writableDestination encounters an I/O problem, like being closed while in use.IllegalArgumentException
- if the jsonSerializable isn't serializable in raw JSON.Copyright © 2018. All rights reserved.