Class JsonIOUtil
java.lang.Object
io.protostuff.JsonIOUtil
Utility for the JSON serialization/deserialization of messages and objects tied to a schema.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA custom factory simply to expose certain fields. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JsonIOUtil.FactoryThe default json factory for creating json parsers and generators. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> voidMerges themessagewith the byte array using the givenschema.static <T> voidMerges themessagewith the byte array using the givenschema.static <T> voidmergeFrom(com.fasterxml.jackson.core.JsonParser parser, T message, Schema<T> schema, boolean numeric) Merges themessagefrom the JsonParser using the givenschema.static <T> voidmergeFrom(InputStream in, T message, Schema<T> schema, boolean numeric) static <T> voidmergeFrom(InputStream in, T message, Schema<T> schema, boolean numeric, LinkedBuffer buffer) static <T> voidstatic com.fasterxml.jackson.core.json.UTF8JsonGeneratornewJsonGenerator(OutputStream out, byte[] buf) Creates aUTF8JsonGeneratorfor the outputstream with the supplied bufoutBufferto use.(package private) static com.fasterxml.jackson.core.json.UTF8JsonGeneratornewJsonGenerator(OutputStream out, byte[] buf, int offset, boolean bufferRecyclable, com.fasterxml.jackson.core.io.IOContext context) Creates aUTF8JsonGeneratorfor the outputstream with the supplied bufoutBufferto use.static com.fasterxml.jackson.core.json.UTF8StreamJsonParsernewJsonParser(InputStream in, byte[] buf, int offset, int limit) Creates aUTF8StreamJsonParserfrom the inputstream with the supplied bufinBufferto use.(package private) static com.fasterxml.jackson.core.json.UTF8StreamJsonParsernewJsonParser(InputStream in, byte[] buf, int offset, int limit, boolean bufferRecyclable, com.fasterxml.jackson.core.io.IOContext context) Creates aUTF8StreamJsonParserfrom the inputstream with the supplied bufinBufferto use.static PipenewPipe(byte[] data, boolean numeric) Creates a json pipe from a byte array.static PipenewPipe(byte[] data, int offset, int length, boolean numeric) Creates a json pipe from a byte array.static PipenewPipe(com.fasterxml.jackson.core.JsonParser parser, boolean numeric) Creates a json pipe from aJsonParser.static PipenewPipe(InputStream in, boolean numeric) Creates a json pipe from anInputStream.static PipeCreates a json pipe from aReader.static <T> List<T> parseListFrom(com.fasterxml.jackson.core.JsonParser parser, Schema<T> schema, boolean numeric) Parses themessagesfrom the parser using the givenschema.static <T> List<T> parseListFrom(InputStream in, Schema<T> schema, boolean numeric) Parses themessagesfrom the stream using the givenschema.static <T> List<T> parseListFrom(InputStream in, Schema<T> schema, boolean numeric, LinkedBuffer buffer) Parses themessagesfrom the stream using the givenschema.static <T> List<T> parseListFrom(Reader reader, Schema<T> schema, boolean numeric) Parses themessagesfrom the reader using the givenschema.static <T> byte[]toByteArray(T message, Schema<T> schema, boolean numeric) Serializes themessageinto a byte array using the givenschema.static <T> byte[]toByteArray(T message, Schema<T> schema, boolean numeric, LinkedBuffer buffer) Serializes themessageinto a byte array using the givenschema.static <T> voidwriteListTo(com.fasterxml.jackson.core.JsonGenerator generator, List<T> messages, Schema<T> schema, boolean numeric) Serializes themessagesinto the generator using the given schema.static <T> voidwriteListTo(OutputStream out, List<T> messages, Schema<T> schema, boolean numeric) Serializes themessagesinto the stream using the given schema.static <T> voidwriteListTo(OutputStream out, List<T> messages, Schema<T> schema, boolean numeric, LinkedBuffer buffer) Serializes themessagesinto the stream using the given schema.static <T> voidwriteListTo(Writer writer, List<T> messages, Schema<T> schema, boolean numeric) Serializes themessagesinto the writer using the given schema.static <T> voidwriteTo(com.fasterxml.jackson.core.JsonGenerator generator, T message, Schema<T> schema, boolean numeric) Serializes themessageinto a JsonGenerator using the givenschema.static <T> voidwriteTo(OutputStream out, T message, Schema<T> schema, boolean numeric) static <T> voidwriteTo(OutputStream out, T message, Schema<T> schema, boolean numeric, LinkedBuffer buffer) static <T> void
-
Field Details
-
DEFAULT_JSON_FACTORY
The default json factory for creating json parsers and generators.
-
-
Constructor Details
-
JsonIOUtil
private JsonIOUtil()
-
-
Method Details
-
newPipe
Creates a json pipe from a byte array.- Throws:
IOException
-
newPipe
Creates a json pipe from a byte array.- Throws:
IOException
-
newPipe
Creates a json pipe from anInputStream.- Throws:
IOException
-
newPipe
Creates a json pipe from aReader.- Throws:
IOException
-
newPipe
public static Pipe newPipe(com.fasterxml.jackson.core.JsonParser parser, boolean numeric) throws IOException Creates a json pipe from aJsonParser.- Throws:
IOException
-
newJsonParser
public static com.fasterxml.jackson.core.json.UTF8StreamJsonParser newJsonParser(InputStream in, byte[] buf, int offset, int limit) throws IOException Creates aUTF8StreamJsonParserfrom the inputstream with the supplied bufinBufferto use.- Throws:
IOException
-
newJsonParser
static com.fasterxml.jackson.core.json.UTF8StreamJsonParser newJsonParser(InputStream in, byte[] buf, int offset, int limit, boolean bufferRecyclable, com.fasterxml.jackson.core.io.IOContext context) throws IOException Creates aUTF8StreamJsonParserfrom the inputstream with the supplied bufinBufferto use.- Throws:
IOException
-
newJsonGenerator
public static com.fasterxml.jackson.core.json.UTF8JsonGenerator newJsonGenerator(OutputStream out, byte[] buf) Creates aUTF8JsonGeneratorfor the outputstream with the supplied bufoutBufferto use. -
newJsonGenerator
static com.fasterxml.jackson.core.json.UTF8JsonGenerator newJsonGenerator(OutputStream out, byte[] buf, int offset, boolean bufferRecyclable, com.fasterxml.jackson.core.io.IOContext context) Creates aUTF8JsonGeneratorfor the outputstream with the supplied bufoutBufferto use. -
mergeFrom
public static <T> void mergeFrom(byte[] data, T message, Schema<T> schema, boolean numeric) throws IOException Merges themessagewith the byte array using the givenschema.- Throws:
IOException
-
mergeFrom
public static <T> void mergeFrom(byte[] data, int offset, int length, T message, Schema<T> schema, boolean numeric) throws IOException Merges themessagewith the byte array using the givenschema.- Throws:
IOException
-
mergeFrom
public static <T> void mergeFrom(InputStream in, T message, Schema<T> schema, boolean numeric) throws IOException - Throws:
IOException
-
mergeFrom
public static <T> void mergeFrom(InputStream in, T message, Schema<T> schema, boolean numeric, LinkedBuffer buffer) throws IOException Merges themessagefrom theInputStreamusing the givenschema.The
LinkedBuffer's internal byte array will be used when reading the message.- Throws:
IOException
-
mergeFrom
public static <T> void mergeFrom(Reader reader, T message, Schema<T> schema, boolean numeric) throws IOException - Throws:
IOException
-
mergeFrom
public static <T> void mergeFrom(com.fasterxml.jackson.core.JsonParser parser, T message, Schema<T> schema, boolean numeric) throws IOException Merges themessagefrom the JsonParser using the givenschema.- Throws:
IOException
-
toByteArray
Serializes themessageinto a byte array using the givenschema. -
toByteArray
public static <T> byte[] toByteArray(T message, Schema<T> schema, boolean numeric, LinkedBuffer buffer) Serializes themessageinto a byte array using the givenschema.The
LinkedBuffer's internal byte array will be used as the primary buffer when writing the message. -
writeTo
public static <T> void writeTo(OutputStream out, T message, Schema<T> schema, boolean numeric) throws IOException - Throws:
IOException
-
writeTo
public static <T> void writeTo(OutputStream out, T message, Schema<T> schema, boolean numeric, LinkedBuffer buffer) throws IOException Serializes themessageinto anOutputStreamusing the givenschema.The
LinkedBuffer's internal byte array will be used as the primary buffer when writing the message.- Throws:
IOException
-
writeTo
public static <T> void writeTo(Writer writer, T message, Schema<T> schema, boolean numeric) throws IOException - Throws:
IOException
-
writeTo
public static <T> void writeTo(com.fasterxml.jackson.core.JsonGenerator generator, T message, Schema<T> schema, boolean numeric) throws IOException Serializes themessageinto a JsonGenerator using the givenschema.- Throws:
IOException
-
writeListTo
public static <T> void writeListTo(OutputStream out, List<T> messages, Schema<T> schema, boolean numeric) throws IOException Serializes themessagesinto the stream using the given schema.- Throws:
IOException
-
writeListTo
public static <T> void writeListTo(OutputStream out, List<T> messages, Schema<T> schema, boolean numeric, LinkedBuffer buffer) throws IOException Serializes themessagesinto the stream using the given schema.The
LinkedBuffer's internal byte array will be used as the primary buffer when writing the message.- Throws:
IOException
-
writeListTo
public static <T> void writeListTo(Writer writer, List<T> messages, Schema<T> schema, boolean numeric) throws IOException Serializes themessagesinto the writer using the given schema.- Throws:
IOException
-
writeListTo
public static <T> void writeListTo(com.fasterxml.jackson.core.JsonGenerator generator, List<T> messages, Schema<T> schema, boolean numeric) throws IOException Serializes themessagesinto the generator using the given schema.- Throws:
IOException
-
parseListFrom
public static <T> List<T> parseListFrom(InputStream in, Schema<T> schema, boolean numeric) throws IOException Parses themessagesfrom the stream using the givenschema.- Throws:
IOException
-
parseListFrom
public static <T> List<T> parseListFrom(InputStream in, Schema<T> schema, boolean numeric, LinkedBuffer buffer) throws IOException Parses themessagesfrom the stream using the givenschema.The
LinkedBuffer's internal byte array will be used when reading the message.- Throws:
IOException
-
parseListFrom
public static <T> List<T> parseListFrom(Reader reader, Schema<T> schema, boolean numeric) throws IOException Parses themessagesfrom the reader using the givenschema.- Throws:
IOException
-
parseListFrom
public static <T> List<T> parseListFrom(com.fasterxml.jackson.core.JsonParser parser, Schema<T> schema, boolean numeric) throws IOException Parses themessagesfrom the parser using the givenschema.- Throws:
IOException
-