com.dyuproject.protostuff
Class JsonIOUtil

java.lang.Object
  extended by com.dyuproject.protostuff.JsonIOUtil

public final class JsonIOUtil
extends java.lang.Object

Utility for the JSON serialization/deserialization of messages and objects tied to a schema.

Author:
David Yu
Date created:
Nov 20, 2009

Nested Class Summary
static class JsonIOUtil.Factory
          A custom factory simply to expose certain fields.
 
Field Summary
static JsonIOUtil.Factory DEFAULT_JSON_FACTORY
          The default json factory for creating json parsers and generators.
 
Method Summary
static
<T> void
mergeFrom(byte[] data, int offset, int length, T message, Schema<T> schema, boolean numeric)
          Merges the message with the byte array using the given schema.
static
<T> void
mergeFrom(byte[] data, T message, Schema<T> schema, boolean numeric)
          Merges the message with the byte array using the given schema.
static
<T> void
mergeFrom(java.io.InputStream in, T message, Schema<T> schema, boolean numeric)
          Merges the message from the InputStream using the given schema.
static
<T> void
mergeFrom(java.io.InputStream in, T message, Schema<T> schema, boolean numeric, LinkedBuffer buffer)
          Merges the message from the InputStream using the given schema.
static
<T> void
mergeFrom(org.codehaus.jackson.JsonParser parser, T message, Schema<T> schema, boolean numeric)
          Merges the message from the JsonParser using the given schema.
static
<T> void
mergeFrom(java.io.Reader reader, T message, Schema<T> schema, boolean numeric)
          Merges the message from the Reader using the given schema.
static org.codehaus.jackson.impl.Utf8Generator newJsonGenerator(java.io.OutputStream out, byte[] buf)
          Creates a Utf8Generator for the outputstream with the supplied buf outBuffer to use.
static org.codehaus.jackson.impl.Utf8StreamParser newJsonParser(java.io.InputStream in, byte[] buf, int offset, int limit)
          Creates a Utf8StreamParser from the inputstream with the supplied buf inBuffer to use.
static Pipe newPipe(byte[] data, boolean numeric)
          Creates a json pipe from a byte array.
static Pipe newPipe(byte[] data, int offset, int length, boolean numeric)
          Creates a json pipe from a byte array.
static Pipe newPipe(java.io.InputStream in, boolean numeric)
          Creates a json pipe from an InputStream.
static Pipe newPipe(org.codehaus.jackson.JsonParser parser, boolean numeric)
          Creates a json pipe from a JsonParser.
static Pipe newPipe(java.io.Reader reader, boolean numeric)
          Creates a json pipe from a Reader.
static
<T> java.util.List<T>
parseListFrom(java.io.InputStream in, Schema<T> schema, boolean numeric)
          Parses the messages from the stream using the given schema.
static
<T> java.util.List<T>
parseListFrom(java.io.InputStream in, Schema<T> schema, boolean numeric, LinkedBuffer buffer)
          Parses the messages from the stream using the given schema.
static
<T> java.util.List<T>
parseListFrom(org.codehaus.jackson.JsonParser parser, Schema<T> schema, boolean numeric)
          Parses the messages from the parser using the given schema.
static
<T> java.util.List<T>
parseListFrom(java.io.Reader reader, Schema<T> schema, boolean numeric)
          Parses the messages from the reader using the given schema.
static
<T> byte[]
toByteArray(T message, Schema<T> schema, boolean numeric)
          Serializes the message into a byte array using the given schema.
static
<T> byte[]
toByteArray(T message, Schema<T> schema, boolean numeric, LinkedBuffer buffer)
          Serializes the message into a byte array using the given schema.
static
<T> void
writeListTo(org.codehaus.jackson.JsonGenerator generator, java.util.List<T> messages, Schema<T> schema, boolean numeric)
          Serializes the messages into the generator using the given schema.
static
<T> void
writeListTo(java.io.OutputStream out, java.util.List<T> messages, Schema<T> schema, boolean numeric)
          Serializes the messages into the stream using the given schema.
static
<T> void
writeListTo(java.io.OutputStream out, java.util.List<T> messages, Schema<T> schema, boolean numeric, LinkedBuffer buffer)
          Serializes the messages into the stream using the given schema.
static
<T> void
writeListTo(java.io.Writer writer, java.util.List<T> messages, Schema<T> schema, boolean numeric)
          Serializes the messages into the writer using the given schema.
static
<T> void
writeTo(org.codehaus.jackson.JsonGenerator generator, T message, Schema<T> schema, boolean numeric)
          Serializes the message into a JsonGenerator using the given schema.
static
<T> void
writeTo(java.io.OutputStream out, T message, Schema<T> schema, boolean numeric)
          Serializes the message into an OutputStream using the given schema.
static
<T> void
writeTo(java.io.OutputStream out, T message, Schema<T> schema, boolean numeric, LinkedBuffer buffer)
          Serializes the message into an OutputStream using the given schema.
static
<T> void
writeTo(java.io.Writer writer, T message, Schema<T> schema, boolean numeric)
          Serializes the message into a Writer using the given schema.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_JSON_FACTORY

public static final JsonIOUtil.Factory DEFAULT_JSON_FACTORY
The default json factory for creating json parsers and generators.

Method Detail

newPipe

public static Pipe newPipe(byte[] data,
                           boolean numeric)
                    throws java.io.IOException
Creates a json pipe from a byte array.

Throws:
java.io.IOException

newPipe

public static Pipe newPipe(byte[] data,
                           int offset,
                           int length,
                           boolean numeric)
                    throws java.io.IOException
Creates a json pipe from a byte array.

Throws:
java.io.IOException

newPipe

public static Pipe newPipe(java.io.InputStream in,
                           boolean numeric)
                    throws java.io.IOException
Creates a json pipe from an InputStream.

Throws:
java.io.IOException

newPipe

public static Pipe newPipe(java.io.Reader reader,
                           boolean numeric)
                    throws java.io.IOException
Creates a json pipe from a Reader.

Throws:
java.io.IOException

newPipe

public static Pipe newPipe(org.codehaus.jackson.JsonParser parser,
                           boolean numeric)
                    throws java.io.IOException
Creates a json pipe from a JsonParser.

Throws:
java.io.IOException

newJsonParser

public static org.codehaus.jackson.impl.Utf8StreamParser newJsonParser(java.io.InputStream in,
                                                                       byte[] buf,
                                                                       int offset,
                                                                       int limit)
                                                                throws java.io.IOException
Creates a Utf8StreamParser from the inputstream with the supplied buf inBuffer to use.

Throws:
java.io.IOException

newJsonGenerator

public static org.codehaus.jackson.impl.Utf8Generator newJsonGenerator(java.io.OutputStream out,
                                                                       byte[] buf)
Creates a Utf8Generator for the outputstream with the supplied buf outBuffer to use.


mergeFrom

public static <T> void mergeFrom(byte[] data,
                                 T message,
                                 Schema<T> schema,
                                 boolean numeric)
                      throws java.io.IOException
Merges the message with the byte array using the given schema.

Throws:
java.io.IOException

mergeFrom

public static <T> void mergeFrom(byte[] data,
                                 int offset,
                                 int length,
                                 T message,
                                 Schema<T> schema,
                                 boolean numeric)
                      throws java.io.IOException
Merges the message with the byte array using the given schema.

Throws:
java.io.IOException

mergeFrom

public static <T> void mergeFrom(java.io.InputStream in,
                                 T message,
                                 Schema<T> schema,
                                 boolean numeric)
                      throws java.io.IOException
Merges the message from the InputStream using the given schema.

Throws:
java.io.IOException

mergeFrom

public static <T> void mergeFrom(java.io.InputStream in,
                                 T message,
                                 Schema<T> schema,
                                 boolean numeric,
                                 LinkedBuffer buffer)
                      throws java.io.IOException
Merges the message from the InputStream using the given schema. The LinkedBuffer's internal byte array will be used when reading the message.

Throws:
java.io.IOException

mergeFrom

public static <T> void mergeFrom(java.io.Reader reader,
                                 T message,
                                 Schema<T> schema,
                                 boolean numeric)
                      throws java.io.IOException
Merges the message from the Reader using the given schema.

Throws:
java.io.IOException

mergeFrom

public static <T> void mergeFrom(org.codehaus.jackson.JsonParser parser,
                                 T message,
                                 Schema<T> schema,
                                 boolean numeric)
                      throws java.io.IOException
Merges the message from the JsonParser using the given schema.

Throws:
java.io.IOException

toByteArray

public static <T> byte[] toByteArray(T message,
                                     Schema<T> schema,
                                     boolean numeric)
Serializes the message into a byte array using the given schema.


toByteArray

public static <T> byte[] toByteArray(T message,
                                     Schema<T> schema,
                                     boolean numeric,
                                     LinkedBuffer buffer)
Serializes the message into a byte array using the given schema. The LinkedBuffer's internal byte array will be used as the primary buffer when writing the message.


writeTo

public static <T> void writeTo(java.io.OutputStream out,
                               T message,
                               Schema<T> schema,
                               boolean numeric)
                    throws java.io.IOException
Serializes the message into an OutputStream using the given schema.

Throws:
java.io.IOException

writeTo

public static <T> void writeTo(java.io.OutputStream out,
                               T message,
                               Schema<T> schema,
                               boolean numeric,
                               LinkedBuffer buffer)
                    throws java.io.IOException
Serializes the message into an OutputStream using the given schema. The LinkedBuffer's internal byte array will be used as the primary buffer when writing the message.

Throws:
java.io.IOException

writeTo

public static <T> void writeTo(java.io.Writer writer,
                               T message,
                               Schema<T> schema,
                               boolean numeric)
                    throws java.io.IOException
Serializes the message into a Writer using the given schema.

Throws:
java.io.IOException

writeTo

public static <T> void writeTo(org.codehaus.jackson.JsonGenerator generator,
                               T message,
                               Schema<T> schema,
                               boolean numeric)
                    throws java.io.IOException
Serializes the message into a JsonGenerator using the given schema.

Throws:
java.io.IOException

writeListTo

public static <T> void writeListTo(java.io.OutputStream out,
                                   java.util.List<T> messages,
                                   Schema<T> schema,
                                   boolean numeric)
                        throws java.io.IOException
Serializes the messages into the stream using the given schema.

Throws:
java.io.IOException

writeListTo

public static <T> void writeListTo(java.io.OutputStream out,
                                   java.util.List<T> messages,
                                   Schema<T> schema,
                                   boolean numeric,
                                   LinkedBuffer buffer)
                        throws java.io.IOException
Serializes the messages into the stream using the given schema. The LinkedBuffer's internal byte array will be used as the primary buffer when writing the message.

Throws:
java.io.IOException

writeListTo

public static <T> void writeListTo(java.io.Writer writer,
                                   java.util.List<T> messages,
                                   Schema<T> schema,
                                   boolean numeric)
                        throws java.io.IOException
Serializes the messages into the writer using the given schema.

Throws:
java.io.IOException

writeListTo

public static <T> void writeListTo(org.codehaus.jackson.JsonGenerator generator,
                                   java.util.List<T> messages,
                                   Schema<T> schema,
                                   boolean numeric)
                        throws java.io.IOException
Serializes the messages into the generator using the given schema.

Throws:
java.io.IOException

parseListFrom

public static <T> java.util.List<T> parseListFrom(java.io.InputStream in,
                                                  Schema<T> schema,
                                                  boolean numeric)
                                       throws java.io.IOException
Parses the messages from the stream using the given schema.

Throws:
java.io.IOException

parseListFrom

public static <T> java.util.List<T> parseListFrom(java.io.InputStream in,
                                                  Schema<T> schema,
                                                  boolean numeric,
                                                  LinkedBuffer buffer)
                                       throws java.io.IOException
Parses the messages from the stream using the given schema. The LinkedBuffer's internal byte array will be used when reading the message.

Throws:
java.io.IOException

parseListFrom

public static <T> java.util.List<T> parseListFrom(java.io.Reader reader,
                                                  Schema<T> schema,
                                                  boolean numeric)
                                       throws java.io.IOException
Parses the messages from the reader using the given schema.

Throws:
java.io.IOException

parseListFrom

public static <T> java.util.List<T> parseListFrom(org.codehaus.jackson.JsonParser parser,
                                                  Schema<T> schema,
                                                  boolean numeric)
                                       throws java.io.IOException
Parses the messages from the parser using the given schema.

Throws:
java.io.IOException


Copyright © 2009-2012. All Rights Reserved.