Class MessageMarshaller.Builder
- java.lang.Object
-
- org.curioswitch.common.protobuf.json.MessageMarshaller.Builder
-
- Enclosing class:
- MessageMarshaller
public static final class MessageMarshaller.Builder extends java.lang.ObjectAMessageMarshaller.BuilderofMessageMarshallers, allows registeringMessagetypes to marshall and set options.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MessageMarshallerbuild()Returns the builtMessageMarshaller, generatingTypeSpecificMarshallerfor all registeredMessagetypes.MessageMarshaller.BuilderignoringUnknownFields(boolean ignoringUnknownFields)Sets whether unknown fields should be allowed when parsing JSON input.MessageMarshaller.BuilderincludingDefaultValueFields(boolean includingDefaultValueFields)Set whether unset fields will be serialized with their default values.MessageMarshaller.BuilderomittingInsignificantWhitespace(boolean omittingInsignificantWhitespace)Whether the serialized JSON output will omit all insignificant whitespace.MessageMarshaller.BuilderpreservingProtoFieldNames(boolean preservingProtoFieldNames)Set whether field names should use the original name in the .proto file instead of converting to lowerCamelCase when serializing messages.MessageMarshaller.BuilderprintingEnumsAsInts(boolean printingEnumsAsInts)Sets whether enum values should be printed as their integer value rather than their name.MessageMarshaller.Builderregister(com.google.protobuf.Message prototype)Registers the type of the providedMessagefor use with the createdMessageMarshaller.MessageMarshaller.Builderregister(java.lang.Class<? extends com.google.protobuf.Message> messageClass)Registers the providedMessagetype for use with the createdMessageMarshaller.MessageMarshaller.BuildersortingMapKeys(boolean sortingMapKeys)Sets whether map keys will be sorted in the JSON output.
-
-
-
Method Detail
-
register
public MessageMarshaller.Builder register(com.google.protobuf.Message prototype)
Registers the type of the providedMessagefor use with the createdMessageMarshaller. While any instance of the type to register can be used, this will commonly be called withgetDefaultInstance()on the type to register.The provided
Messageand all nestedMessagetypes reachable from this one will be registered and available for marshalling. For clarity, it's generally a good idea to explicitly register anyMessagethat you will pass to methods ofMessageMarshallereven if they are already registered as a nestedMessage.
-
register
public MessageMarshaller.Builder register(java.lang.Class<? extends com.google.protobuf.Message> messageClass)
Registers the providedMessagetype for use with the createdMessageMarshaller. While any instance of the type to register can be used, this will commonly be called withgetDefaultInstance()on the type to register.The provided
Messageand all nestedMessagetypes reachable from this one will be registered and available for marshalling. For clarity, it's generally a good idea to explicitly register anyMessagethat you will pass to methods ofMessageMarshallereven if they are already registered as a nestedMessage.
-
includingDefaultValueFields
public MessageMarshaller.Builder includingDefaultValueFields(boolean includingDefaultValueFields)
Set whether unset fields will be serialized with their default values. Empty repeated fields and map fields will be printed as well. The new Printer clones all other configurations from the current.
-
preservingProtoFieldNames
public MessageMarshaller.Builder preservingProtoFieldNames(boolean preservingProtoFieldNames)
Set whether field names should use the original name in the .proto file instead of converting to lowerCamelCase when serializing messages. When set, the json_name annotation will be ignored.
-
omittingInsignificantWhitespace
public MessageMarshaller.Builder omittingInsignificantWhitespace(boolean omittingInsignificantWhitespace)
Whether the serialized JSON output will omit all insignificant whitespace. Insignificant whitespace is defined by the JSON spec as whitespace that appear between JSON structural elements:ws = *( %x20 / ; Space %x09 / ; Horizontal tab %x0A / ; Line feed or New line %x0D ) ; Carriage return
See https://tools.ietf.org/html/rfc7159
-
ignoringUnknownFields
public MessageMarshaller.Builder ignoringUnknownFields(boolean ignoringUnknownFields)
Sets whether unknown fields should be allowed when parsing JSON input. When not set, an exception will be thrown when encountering unknown fields.
-
printingEnumsAsInts
public MessageMarshaller.Builder printingEnumsAsInts(boolean printingEnumsAsInts)
Sets whether enum values should be printed as their integer value rather than their name.
-
sortingMapKeys
public MessageMarshaller.Builder sortingMapKeys(boolean sortingMapKeys)
Sets whether map keys will be sorted in the JSON output.Use of this modifier is discouraged, the generated JSON messages are equivalent with and without this option set, but there are some corner caseuse cases that demand a stable output, while order of map keys is otherwise arbitrary.
The generated order is not well-defined and should not be depended on, but it's stable.
-
build
public MessageMarshaller build()
Returns the builtMessageMarshaller, generatingTypeSpecificMarshallerfor all registeredMessagetypes. AnyMessagetypes that have not been registered will not be usable with the returnedMessageMarshaller.
-
-