Class JacksonUtils

java.lang.Object
org.apache.druid.java.util.common.jackson.JacksonUtils

public final class JacksonUtils extends Object
  • Field Details

    • 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
    • TYPE_REFERENCE_MAP_STRING_BOOLEAN

      public static final com.fasterxml.jackson.core.type.TypeReference<Map<String,Boolean>> TYPE_REFERENCE_MAP_STRING_BOOLEAN
  • Method Details

    • readValue

      public static <T> T readValue(com.fasterxml.jackson.databind.ObjectMapper mapper, byte[] bytes, Class<T> valueType)
      Silences Jackson's IOException.
    • readValue

      public static <T> T readValue(com.fasterxml.jackson.databind.ObjectMapper mapper, byte[] bytes, com.fasterxml.jackson.databind.JavaType valueType)
      Silences Jackson's IOException.
    • readValue

      public static <T> T readValue(com.fasterxml.jackson.databind.ObjectMapper mapper, byte[] bytes, com.fasterxml.jackson.core.type.TypeReference<T> valueType)
      Silences Jackson's IOException.
    • 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 a SerializerProvider, this is better than calling JsonGenerator.writeObject(Object) or ObjectMapper.writeValue(JsonGenerator, Object), because it avoids re-creating the SerializerProvider 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 a JsonGenerator. If you have a SerializerProvider, this is better than calling JsonGenerator.writeObject(Object), because it avoids re-creating the SerializerProvider for each serialized object.
      Throws:
      IOException
    • writeValueAsString

      public static String writeValueAsString(com.fasterxml.jackson.databind.ObjectMapper jsonMapper, Object value) throws DruidException
      Throws:
      DruidException
    • readObjectUsingDeserializationContext

      @Nullable public static <T> T readObjectUsingDeserializationContext(com.fasterxml.jackson.core.JsonParser jp, com.fasterxml.jackson.databind.DeserializationContext deserializationContext, Class<T> clazz) throws IOException
      Reads an object using the JsonParser. It reuses the provided DeserializationContext which offers better performance that calling JsonParser.readValueAs(Class) because it avoids re-creating the DeserializationContext for each readValue call
      Throws:
      IOException
    • readObjectUsingDeserializationContext

      @Nullable public static Object readObjectUsingDeserializationContext(com.fasterxml.jackson.core.JsonParser jp, com.fasterxml.jackson.databind.DeserializationContext deserializationContext, com.fasterxml.jackson.databind.JavaType javaType) throws IOException
      Throws:
      IOException
      See Also:
    • 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.