Class JacksonUtils
- java.lang.Object
-
- org.apache.druid.java.util.common.jackson.JacksonUtils
-
public final class JacksonUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static com.fasterxml.jackson.core.type.TypeReference<Map<String,Boolean>>
TYPE_REFERENCE_MAP_STRING_BOOLEAN
static com.fasterxml.jackson.core.type.TypeReference<Map<String,Object>>
TYPE_REFERENCE_MAP_STRING_OBJECT
static com.fasterxml.jackson.core.type.TypeReference<Map<String,String>>
TYPE_REFERENCE_MAP_STRING_STRING
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.fasterxml.jackson.databind.JsonSerializer<Object>
getSerializer(com.fasterxml.jackson.databind.SerializerProvider serializerProvider, Class<?> clazz)
Returns a serializer for a particular class.static <T> T
readValue(com.fasterxml.jackson.databind.ObjectMapper mapper, byte[] bytes, com.fasterxml.jackson.core.type.TypeReference<T> valueType)
Silences Jackson'sIOException
.static <T> T
readValue(com.fasterxml.jackson.databind.ObjectMapper mapper, byte[] bytes, com.fasterxml.jackson.databind.JavaType valueType)
Silences Jackson'sIOException
.static <T> T
readValue(com.fasterxml.jackson.databind.ObjectMapper mapper, byte[] bytes, Class<T> valueType)
Silences Jackson'sIOException
.static byte[]
toBytes(com.fasterxml.jackson.databind.ObjectMapper jsonMapper, Object obj)
Convert the given object to an array of bytes.static void
writeObjectUsingSerializerProvider(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider serializers, Object o)
Serializes an object using aJsonGenerator
.
-
-
-
Field Detail
-
TYPE_REFERENCE_MAP_STRING_OBJECT
public static final com.fasterxml.jackson.core.type.TypeReference<Map<String,Object>> TYPE_REFERENCE_MAP_STRING_OBJECT
-
TYPE_REFERENCE_MAP_STRING_STRING
public static final com.fasterxml.jackson.core.type.TypeReference<Map<String,String>> TYPE_REFERENCE_MAP_STRING_STRING
-
-
Method Detail
-
readValue
public static <T> T readValue(com.fasterxml.jackson.databind.ObjectMapper mapper, byte[] bytes, Class<T> valueType)
Silences Jackson'sIOException
.
-
readValue
public static <T> T readValue(com.fasterxml.jackson.databind.ObjectMapper mapper, byte[] bytes, com.fasterxml.jackson.databind.JavaType valueType)
Silences Jackson'sIOException
.
-
readValue
public static <T> T readValue(com.fasterxml.jackson.databind.ObjectMapper mapper, byte[] bytes, com.fasterxml.jackson.core.type.TypeReference<T> valueType)
Silences Jackson'sIOException
.
-
getSerializer
public static com.fasterxml.jackson.databind.JsonSerializer<Object> getSerializer(com.fasterxml.jackson.databind.SerializerProvider serializerProvider, Class<?> clazz) throws com.fasterxml.jackson.databind.JsonMappingException
Returns a serializer for a particular class. If you have aSerializerProvider
, this is better than callingJsonGenerator.writeObject(Object)
orObjectMapper.writeValue(JsonGenerator, Object)
, because it avoids re-creating theSerializerProvider
for each serialized object.- Throws:
com.fasterxml.jackson.databind.JsonMappingException
-
writeObjectUsingSerializerProvider
public static void writeObjectUsingSerializerProvider(com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider serializers, @Nullable Object o) throws IOException
Serializes an object using aJsonGenerator
. If you have aSerializerProvider
, this is better than callingJsonGenerator.writeObject(Object)
, because it avoids re-creating theSerializerProvider
for each serialized object.- Throws:
IOException
-
toBytes
public static byte[] toBytes(com.fasterxml.jackson.databind.ObjectMapper jsonMapper, Object obj)
Convert the given object to an array of bytes. Use when the object is known serializable so that the Jackson exception can be suppressed.
-
-