public class JsonSerializer extends Serializer
Format is like this:
{
"id":value,
"structId":{ ... },
"listId":[value1,value2],
"mapId":{"id1":value1,"id2":value2}
}
But without formatting spaces. The formatted JSON can be read normally.
Binary fields are base64 encoded.
This format supports 'compact' struct formatting. A compact struct is formatted as a list with fields in order from 1 to N. E.g.:
["tag",5,6.45]is equivalent to:
{"1":"tag","2":5,"3":6.45}
| Modifier and Type | Field and Description |
|---|---|
static String |
JSON_MEDIA_TYPE |
static String |
MEDIA_TYPE |
DEFAULT_STRICT| Constructor and Description |
|---|
JsonSerializer() |
JsonSerializer(boolean strict) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
binaryProtocol() |
<T extends PMessage<T>> |
deserialize(InputStream input,
PMessageDescriptor<T> type)
Deserialize a message.
|
<T extends PMessage<T>> |
deserialize(InputStream input,
PService service)
Deserialize a service call.
|
<T extends PMessage<T>> |
deserialize(Reader input,
PMessageDescriptor<T> type) |
JsonSerializer |
grpc() |
String |
mediaType() |
JsonSerializer |
named() |
static <Message extends PMessage<Message>> |
parseJsonString(String string,
PMessageDescriptor<Message> descriptor)
Parses a JSON string, and makes exceptions unchecked.
|
JsonSerializer |
pretty() |
<T extends PMessage<T>> |
serialize(OutputStream output,
PMessageOrBuilder<T> message)
Serialize a message.
|
<T extends PMessage<T>> |
serialize(OutputStream output,
PServiceCall<T> call)
Serialize a service call.
|
<T extends PMessage<T>> |
serialize(PrintWriter output,
PMessageOrBuilder<T> message) |
static <Message extends PMessage<Message>> |
toJsonString(PMessageOrBuilder<Message> message)
Prints a JSON string of the provided message.
|
static <Message extends PMessage<Message>> |
toPrettyJsonString(PMessageOrBuilder<Message> message)
Prints a pretty formatted JSON string of the provided message.
|
void |
verifyEndOfContent(InputStream input)
Verify that the input stream does not contain any more readable content and
close the stream.
|
void |
verifyEndOfContent(Reader input) |
JsonSerializer |
withFlattenUnionOf() |
JsonSerializer |
withIdEnums() |
JsonSerializer |
withIdFields() |
JsonSerializer |
withNamedEnums() |
JsonSerializer |
withNamedFields() |
JsonSerializer |
withPojoNamedFields() |
isRequestCallType, toStringpublic static final String MEDIA_TYPE
public static final String JSON_MEDIA_TYPE
public JsonSerializer()
public JsonSerializer(boolean strict)
@Nonnull public static <Message extends PMessage<Message>> String toJsonString(PMessageOrBuilder<Message> message)
Message - The message type.message - The message to stringify.@Nonnull public static <Message extends PMessage<Message>> String toPrettyJsonString(PMessageOrBuilder<Message> message)
Message - The message type.message - The message to stringify.@Nonnull public static <Message extends PMessage<Message>> Message parseJsonString(String string, PMessageDescriptor<Message> descriptor)
Message - The message type.string - The message string to parse.descriptor - The message descriptor.public JsonSerializer pretty()
public JsonSerializer named()
public JsonSerializer grpc()
public JsonSerializer withPojoNamedFields()
public JsonSerializer withNamedFields()
public JsonSerializer withNamedEnums()
public JsonSerializer withIdFields()
public JsonSerializer withIdEnums()
public JsonSerializer withFlattenUnionOf()
public <T extends PMessage<T>> void serialize(@Nonnull PrintWriter output, @Nonnull PMessageOrBuilder<T> message) throws IOException
IOExceptionpublic <T extends PMessage<T>> int serialize(@Nonnull OutputStream output, @Nonnull PMessageOrBuilder<T> message) throws IOException
Serializerserialize in class SerializerT - The message type.output - The output stream to write to.message - The message to write.IOException - If writing or serialization failed.public <T extends PMessage<T>> int serialize(@Nonnull OutputStream output, @Nonnull PServiceCall<T> call) throws IOException
Serializerserialize in class SerializerT - The message type contained in the service call.output - The output stream to write to.call - The service call to write.IOException - If writing or serialization failed.@Nonnull public <T extends PMessage<T>> T deserialize(@Nonnull InputStream input, @Nonnull PMessageDescriptor<T> type) throws IOException
Serializerdeserialize in class SerializerT - The message type.input - The input stream to read from.type - The descriptor of the message to read.IOException - If reading or deserialization failed.public <T extends PMessage<T>> T deserialize(@Nonnull Reader input, @Nonnull PMessageDescriptor<T> type) throws IOException
IOException@Nonnull public <T extends PMessage<T>> PServiceCall<T> deserialize(@Nonnull InputStream input, @Nonnull PService service) throws IOException
Serializerdeserialize in class SerializerT - The message type contained in the returned service call.input - The input stream to read from.service - The service definition to read for.IOException - If reading or deserialization failed.public boolean binaryProtocol()
binaryProtocol in class Serializerpublic void verifyEndOfContent(@Nonnull InputStream input) throws IOException
SerializerverifyEndOfContent in class Serializerinput - The input stream to check.IOException - If unable to read from stream or stream contains meaningful content.public void verifyEndOfContent(@Nonnull Reader input) throws IOException
IOException@Nonnull public String mediaType()
mediaType in class SerializerCopyright © 2015–2020 morimekta.net. All rights reserved.