Class MessageMarshaller
- java.lang.Object
 - 
- org.curioswitch.common.protobuf.json.MessageMarshaller
 
 
- 
public class MessageMarshaller extends java.lang.ObjectA marshaller of pre-registeredMessagetypes. Specific bytecode for marshalling theMessagewill be generated as a subclass ofTypeSpecificMarshallerand used for optimal serializing and parsing of JSON for protobufs. Usebuilder()for setting up theMessageMarshallerand registering types.For example:
MessageMarshaller marshaller = MessageMarshaller.builder() .omittingInsignificantWhitespace(true) .register(MyRequest.getDefaultInstance()) .register(MyResponse.getDefaultInstance()) .build(); MyRequest.Builder requestBuilder = MyRequest.newBuilder(); marshaller.mergeValue(json, requestBuilder); MyResponse response = handle(requestBuilder.build()); return marshaller.writeValueAsBytes(response); 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMessageMarshaller.BuilderAMessageMarshaller.BuilderofMessageMarshallers, allows registeringMessagetypes to marshall and set options. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MessageMarshaller.Builderbuilder()Returns a newMessageMarshaller.Builderfor registeringMessagetypes for use in aMessageMarshalleras well as setting various serialization and parsing options.voidmergeValue(byte[] json, com.google.protobuf.Message.Builder builder)Merges the JSON UTF-8 bytes into the providedMessage.Builder.voidmergeValue(com.fasterxml.jackson.core.JsonParser jsonParser, com.google.protobuf.Message.Builder builder)Merges the content inside theJsonParserinto the providedMessage.Builder.voidmergeValue(java.io.InputStream json, com.google.protobuf.Message.Builder builder)Merges the JSON bytes inside the providedInputStreaminto the providedMessage.Builder.voidmergeValue(java.lang.String json, com.google.protobuf.Message.Builder builder)Merges the JSONStringinto the providedMessage.Builder.<T extends com.google.protobuf.Message>
voidwriteValue(T message, com.fasterxml.jackson.core.JsonGenerator gen)Converts aMessageinto a JSON, writing to the providedJsonGenerator.<T extends com.google.protobuf.Message>
voidwriteValue(T message, java.io.OutputStream out)Converts aMessageinto JSON, writing to the providedOutputStream.<T extends com.google.protobuf.Message>
byte[]writeValueAsBytes(T message)Converts aMessageinto JSON as UTF-8 encoded bytes.<T extends com.google.protobuf.Message>
java.lang.StringwriteValueAsString(T message)Converts aMessageinto a JSONString. 
 - 
 
- 
- 
Method Detail
- 
builder
public static MessageMarshaller.Builder builder()
Returns a newMessageMarshaller.Builderfor registeringMessagetypes for use in aMessageMarshalleras well as setting various serialization and parsing options. 
- 
mergeValue
public void mergeValue(byte[] json, com.google.protobuf.Message.Builder builder) throws java.io.IOExceptionMerges the JSON UTF-8 bytes into the providedMessage.Builder.- Throws:
 com.google.protobuf.InvalidProtocolBufferException- if the input is not valid JSON format or there are unknown fields in the input.java.io.IOException
 
- 
mergeValue
public void mergeValue(java.lang.String json, com.google.protobuf.Message.Builder builder) throws java.io.IOExceptionMerges the JSONStringinto the providedMessage.Builder.- Throws:
 com.google.protobuf.InvalidProtocolBufferException- if the input is not valid JSON format or there are unknown fields in the input.java.io.IOException
 
- 
mergeValue
public void mergeValue(java.io.InputStream json, com.google.protobuf.Message.Builder builder) throws java.io.IOExceptionMerges the JSON bytes inside the providedInputStreaminto the providedMessage.Builder. Will not close theInputStream.- Throws:
 com.google.protobuf.InvalidProtocolBufferException- if the input is not valid JSON format or there are unknown fields in the input.java.io.IOException
 
- 
mergeValue
public void mergeValue(com.fasterxml.jackson.core.JsonParser jsonParser, com.google.protobuf.Message.Builder builder) throws java.io.IOExceptionMerges the content inside theJsonParserinto the providedMessage.Builder.- Throws:
 com.google.protobuf.InvalidProtocolBufferException- if the input is not valid JSON format or there are unknown fields in the input.java.io.IOException
 
- 
writeValueAsBytes
public <T extends com.google.protobuf.Message> byte[] writeValueAsBytes(T message) throws java.io.IOExceptionConverts aMessageinto JSON as UTF-8 encoded bytes.- Throws:
 com.google.protobuf.InvalidProtocolBufferException- if there are unknown Any types in the message.java.io.IOException
 
- 
writeValueAsString
public <T extends com.google.protobuf.Message> java.lang.String writeValueAsString(T message) throws java.io.IOExceptionConverts aMessageinto a JSONString.- Throws:
 com.google.protobuf.InvalidProtocolBufferException- if there are unknown Any types in the message.java.io.IOException
 
- 
writeValue
public <T extends com.google.protobuf.Message> void writeValue(T message, java.io.OutputStream out) throws java.io.IOExceptionConverts aMessageinto JSON, writing to the providedOutputStream. Does not close theOutputStream.- Throws:
 java.io.IOException
 
- 
writeValue
public <T extends com.google.protobuf.Message> void writeValue(T message, com.fasterxml.jackson.core.JsonGenerator gen) throws java.io.IOExceptionConverts aMessageinto a JSON, writing to the providedJsonGenerator.- Throws:
 com.google.protobuf.InvalidProtocolBufferException- if there are unknown Any types in the message.java.io.IOException
 
 - 
 
 -