Class JsonUtils
java.lang.Object
org.infinispan.protostream.impl.JsonUtils
Utility class for conversion to and from canonical JSON.
- Since:
- 4.4
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate static final com.fasterxml.jackson.core.JsonFactoryprivate static final Stringprivate static final ThreadLocal<DateFormat> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidescapeJson(String value, StringBuilder out, boolean htmlSafe) Escapes a string literal in order to have a valid JSON representation.private static voidexpectField(String expectedFieldName, String actualFieldName) private static StringformatDate(Date date) static byte[]fromCanonicalJSON(ImmutableSerializationContext ctx, Reader reader) private static intgetPrimitiveFieldId(Type primitiveType) private static voidprocessArray(ImmutableSerializationContext ctx, String type, String field, com.fasterxml.jackson.core.JsonParser parser, TagWriter writer) private static voidprocessDocument(ImmutableSerializationContext ctx, com.fasterxml.jackson.core.JsonParser parser, TagWriter writer) private static voidprocessEnum(com.fasterxml.jackson.core.JsonParser parser, TagWriter writer, EnumDescriptor enumDescriptor) private static voidprocessMap(ImmutableSerializationContext ctx, MapDescriptor md, com.fasterxml.jackson.core.JsonParser parser, TagWriter writer) private static voidprocessMapValue(ImmutableSerializationContext ctx, com.fasterxml.jackson.core.JsonParser parser, TagWriter writer, MapDescriptor md) private static voidprocessObject(ImmutableSerializationContext ctx, com.fasterxml.jackson.core.JsonParser parser, TagWriter writer, Descriptor messageDescriptor, Integer fieldNumber, boolean topLevel) private static voidprocessPrimitive(com.fasterxml.jackson.core.JsonParser parser, TagWriter writer, Type fieldType) static StringtoCanonicalJSON(ImmutableSerializationContext ctx, byte[] bytes, boolean prettyPrint) Converts a Protobuf encoded message to its canonical JSON representation.private static voidtoCanonicalJSON(ImmutableSerializationContext ctx, byte[] bytes, StringBuilder jsonOut, int initNestingLevel) private static voidwriteEnumField(com.fasterxml.jackson.core.JsonParser parser, TagWriter writer, FieldDescriptor fd, int fieldNumber) private static voidwriteField(com.fasterxml.jackson.core.JsonParser parser, TagWriter writer, Type fieldType, int fieldNumber)
-
Field Details
-
RFC_3339_DATE_FORMAT
- See Also:
-
jsonFactory
private static final com.fasterxml.jackson.core.JsonFactory jsonFactory -
JSON_TYPE_FIELD
- See Also:
-
JSON_VALUE_FIELD
- See Also:
-
timestampFormat
-
-
Constructor Details
-
JsonUtils
private JsonUtils()
-
-
Method Details
-
fromCanonicalJSON
public static byte[] fromCanonicalJSON(ImmutableSerializationContext ctx, Reader reader) throws IOException - Throws:
IOException
-
processDocument
private static void processDocument(ImmutableSerializationContext ctx, com.fasterxml.jackson.core.JsonParser parser, TagWriter writer) throws IOException - Throws:
IOException
-
processEnum
private static void processEnum(com.fasterxml.jackson.core.JsonParser parser, TagWriter writer, EnumDescriptor enumDescriptor) throws IOException - Throws:
IOException
-
processObject
private static void processObject(ImmutableSerializationContext ctx, com.fasterxml.jackson.core.JsonParser parser, TagWriter writer, Descriptor messageDescriptor, Integer fieldNumber, boolean topLevel) throws IOException - Throws:
IOException
-
processMap
private static void processMap(ImmutableSerializationContext ctx, MapDescriptor md, com.fasterxml.jackson.core.JsonParser parser, TagWriter writer) throws IOException - Throws:
IOException
-
processMapValue
private static void processMapValue(ImmutableSerializationContext ctx, com.fasterxml.jackson.core.JsonParser parser, TagWriter writer, MapDescriptor md) throws IOException - Throws:
IOException
-
processPrimitive
private static void processPrimitive(com.fasterxml.jackson.core.JsonParser parser, TagWriter writer, Type fieldType) throws IOException - Throws:
IOException
-
getPrimitiveFieldId
-
processArray
private static void processArray(ImmutableSerializationContext ctx, String type, String field, com.fasterxml.jackson.core.JsonParser parser, TagWriter writer) throws IOException - Throws:
IOException
-
toCanonicalJSON
public static String toCanonicalJSON(ImmutableSerializationContext ctx, byte[] bytes, boolean prettyPrint) throws IOException Converts a Protobuf encoded message to its canonical JSON representation.- Parameters:
ctx- the serialization contextbytes- the Protobuf encoded message bytes to parseprettyPrint- indicates if the JSON output should use a 'pretty' human-readable format or a compact format- Returns:
- the JSON string representation
- Throws:
IOException- if I/O operations fail
-
toCanonicalJSON
private static void toCanonicalJSON(ImmutableSerializationContext ctx, byte[] bytes, StringBuilder jsonOut, int initNestingLevel) throws IOException - Throws:
IOException
-
writeEnumField
private static void writeEnumField(com.fasterxml.jackson.core.JsonParser parser, TagWriter writer, FieldDescriptor fd, int fieldNumber) throws IOException - Throws:
IOException
-
writeField
private static void writeField(com.fasterxml.jackson.core.JsonParser parser, TagWriter writer, Type fieldType, int fieldNumber) throws IOException - Throws:
IOException
-
expectField
-
escapeJson
Escapes a string literal in order to have a valid JSON representation. Optionally it can also escape some html chars. -
formatDate
-