public class JsonSerializer extends Serializer
There is also the strict mode. If strict is OFF: - Unknown enum values will be ignored (as field missing). - Message validity will be ignored. If strict more is ON: - Unknown enum values will fail deserialization. - Message invalidity will fail deserialization.
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,TF>,TF extends PField> |
deserialize(InputStream input,
PMessageDescriptor<T,TF> type)
Deserialize a message.
|
<T extends PMessage<T,F>,F extends PField> |
deserialize(InputStream input,
PService service)
Deserialize a service call.
|
String |
mediaType() |
JsonSerializer |
named() |
JsonSerializer |
pretty() |
<T extends PMessage<T,F>,F extends PField> |
serialize(OutputStream output,
PServiceCall<T,F> call)
Serialize a service call.
|
<T extends PMessage<T,F>,F extends PField> |
serialize(OutputStream output,
T message)
Serialize a message.
|
JsonSerializer |
withNamedEnums() |
JsonSerializer |
withNamedFields() |
isRequestCallTypepublic static final String MEDIA_TYPE
public static final String JSON_MEDIA_TYPE
public JsonSerializer()
public JsonSerializer(boolean strict)
public JsonSerializer pretty()
public JsonSerializer named()
public JsonSerializer withNamedFields()
public JsonSerializer withNamedEnums()
public <T extends PMessage<T,F>,F extends PField> int serialize(@Nonnull OutputStream output, @Nonnull T message) throws IOException
Serializerserialize in class SerializerT - The message type.F - The message field type.output - The output stream to write to.message - The message to write.IOException - If writing or serialization failed.public <T extends PMessage<T,F>,F extends PField> int serialize(@Nonnull OutputStream output, @Nonnull PServiceCall<T,F> call) throws IOException
Serializerserialize in class SerializerT - The message type contained in the service call.F - The message field type.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,TF>,TF extends PField> T deserialize(@Nonnull InputStream input, @Nonnull PMessageDescriptor<T,TF> type) throws IOException
Serializerdeserialize in class SerializerT - The message type.TF - The message field type.input - The input stream to read from.type - The descriptor of the message to read.IOException - If reading or deserialization failed.@Nonnull public <T extends PMessage<T,F>,F extends PField> PServiceCall<T,F> deserialize(@Nonnull InputStream input, @Nonnull PService service) throws IOException
Serializerdeserialize in class SerializerT - The message type contained in the returned service call.F - The message field type.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 Serializer@Nonnull public String mediaType()
mediaType in class SerializerCopyright © 2015–2017 morimekta.net. All rights reserved.