public enum MessageFormat extends java.lang.Enum<MessageFormat>
Enum Constant and Description |
---|
BASE64
The Base64 bytes message stringification format.
|
JSON
The JSON message stringification format.
|
Modifier and Type | Method and Description |
---|---|
static java.util.Optional<MessageFormat> |
formatOf(javax.servlet.http.HttpServletRequest request)
Finds the required format for the given request.
|
<T extends com.google.protobuf.Message> |
parse(java.lang.String rawMessage,
java.lang.Class<T> type)
Parses a given string representation into a message of the given
type . |
static MessageFormat |
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.
|
static MessageFormat[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final MessageFormat JSON
public static final MessageFormat BASE64
public static MessageFormat[] values()
for (MessageFormat c : MessageFormat.values()) System.out.println(c);
public static MessageFormat valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is nullpublic static java.util.Optional<MessageFormat> formatOf(javax.servlet.http.HttpServletRequest request)
The format is determined by the value of the Content-Type
header.
If the value is equal to application/json
(case insensitive), returns MessageFormat.JSON
.
If the value is equal to application/x-protobuf
(case insensitive), returns
MessageFormat.BASE64
. If the header is not set, returns MessageFormat.JSON
.
request
- the request to get the format forOptional.empty()
if
the request does not justify the described formatpublic <T extends com.google.protobuf.Message> java.util.Optional<T> parse(java.lang.String rawMessage, java.lang.Class<T> type)
type
.T
- expected class of the messagerawMessage
- string representation of the messagetype
- expected class of the messageOptional.empty()
if parsing fails