Class JacksonUtils


  • public final class JacksonUtils
    extends Object
    • 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
      • TYPE_REFERENCE_MAP_STRING_BOOLEAN

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

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