Class JacksonHelper

  • All Implemented Interfaces:

    
    public class JacksonHelper
    
                        
    XML limitation
    The common uses are:
    (1) single element node, XML can not distinguish between a single value or only one value in the array, unless nested wrap.
    (2) Xml can not recognize the data type, while Json has string, number, boolean, object, array
    
    Jackson Plain
    - `transient` output
    - `@Transient` No output
    - `byte[]` as base64, `[]` as `""`
    - `char[]` as String, `[]` as `""`
    - WRITE_DATES_AS_TIMESTAMPS = false
    - `ZonedDateTime` parse as `2023-04-04T21:07:08Z` lost timezone
    - `OffsetDateTime` parse as `2023-04-05T10:07:08Z` lost timezone
    Jackson Wings
    - `transient` No output
    - WRITE_DATES_AS_TIMESTAMPS = false
    - `LocalDateTime` as `"2023-04-05T06:07:08"`
    - `ZonedDateTime` as `"2023-04-05T06:07:08[America/New_York]"` keep timezone
    - `OffsetDateTime` as `"2023-04-05T06:07:08-04:00"` keep timezone
    Jackson Bean
    - `LocalDateTime` as `"2023-04-05 06:07:08"`
    - `ZonedDateTime` as `"2023-04-05 06:07:08 Asia/Shanghai"`
    - `OffsetDateTime` as `"2023-04-05 06:07:08 +08:00"`
    - `float`,`double` as `"3.14159"`
    - `BigDecimal`,`BigInteger` as `"299792458"`
    
    Since:

    2022-11-05

    Author:

    trydofor

    • Constructor Detail

      • JacksonHelper

        JacksonHelper()
    • Method Detail

      • buildPlain

        @Contract(value = "_->param1") static <T extends MapperBuilder<out Object, out Object>> T buildPlain(@NotNull() T builder)
      • buildWings

        @Contract(value = "_->param1") static <T extends ObjectMapper> T buildWings(@NotNull() T mapper)
      • JsonBean

        @NotNull() static ObjectMapper JsonBean()

        spring bean style Mapper at web tier with ' ' datetime and auto timezone/i18n convert

      • XmlBean

        @NotNull() static XmlMapper XmlBean()

        spring bean style Mapper at web tier with ' ' datetime and auto timezone/i18n convert

      • MapperBean

        @NotNull() static ObjectMapper MapperBean(boolean json)

        spring bean style Mapper at web tier with ' ' datetime and auto timezone/i18n convert

      • JsonPlain

        @NotNull() static ObjectMapper JsonPlain()

        fastjon default with WRITE_DATES_AS_TIMESTAMPS=false and other Disable/Enable

      • XmlPlain

        @NotNull() static XmlMapper XmlPlain()

        fastjon default with WRITE_DATES_AS_TIMESTAMPS=false and other Disable/Enable

      • MapperPlain

        @NotNull() static ObjectMapper MapperPlain(boolean json)

        fastjon default with WRITE_DATES_AS_TIMESTAMPS=false and other Disable/Enable

      • JsonWings

        @NotNull() static ObjectMapper JsonWings()

        wings config with 'T' datetime format without timezone/i18n conversion

      • XmlWings

        @NotNull() static XmlMapper XmlWings()

        wings config with 'T' datetime format without timezone/i18n conversion

      • MapperWings

        @NotNull() static ObjectMapper MapperWings(boolean json)

        wings config with 'T' datetime format without timezone/i18n conversion

      • Mapper

        @NotNull() static ObjectMapper Mapper(@NotNull() JacksonHelper.Style style, boolean json)

        wings configed Mapper without auto timezone convert

      • asXml

        @Contract(value = "null->false") static boolean asXml(String str)

        whether `str` has xml characteristics, i.e. the first and last characters are angle brackets or not

      • asXml

        @Contract(value = "null->false") static boolean asXml(Array<byte> str)

        whether `str` has xml characteristics, i.e. the first and last characters are angle brackets or not

      • javaType

         static JavaType javaType(@NotNull() TypeDescriptor targetType)

        construct jackson's JavaType in spring way

      • javaType

         static JavaType javaType(@NotNull() ResolvableType targetType)

        construct jackson's JavaType in spring way

      • object

        @Contract(value = "!null,_,_->!null") static <T> T object(String text, @NotNull() Class<out Object> targetType, Array<Class<out Object>> generics)

        wings style read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "!null,_->!null") static <T> T object(String text, @NotNull() JavaType targetType)

        wings style read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "_,!null,_ -> !null") static <T> T object(@NotNull() JacksonHelper.Style style, String text, @NotNull() JavaType targetType)

        Auto read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "!null,_->!null") static <T> T object(String text, @NotNull() ResolvableType targetType)

        wings style read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "_,!null,_ -> !null") static <T> T object(@NotNull() JacksonHelper.Style style, String text, @NotNull() ResolvableType targetType)

        Auto read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "!null,_->!null") static <T> T object(String text, @NotNull() TypeDescriptor targetType)

        wings style read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "_,!null,_ -> !null") static <T> T object(@NotNull() JacksonHelper.Style style, String text, @NotNull() TypeDescriptor targetType)

        Auto read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "!null->!null") static JsonNode object(String text)

        wings style read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "!null,_,_->!null") static <T> T object(Array<byte> text, @NotNull() Class<out Object> targetType, Array<Class<out Object>> generics)

        wings style read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "!null,_->!null") static <T> T object(Array<byte> text, @NotNull() JavaType targetType)

        wings style read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "_, !null, _ -> !null") static <T> T object(@NotNull() JacksonHelper.Style style, Array<byte> text, @NotNull() JavaType targetType)

        Auto read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "!null,_->!null") static <T> T object(Array<byte> text, @NotNull() ResolvableType targetType)

        wings style read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "_, !null, _ -> !null") static <T> T object(@NotNull() JacksonHelper.Style style, Array<byte> text, @NotNull() ResolvableType targetType)

        Auto read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "!null,_->!null") static <T> T object(Array<byte> text, @NotNull() TypeDescriptor targetType)

        wings style read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "_, !null, _ -> !null") static <T> T object(@NotNull() JacksonHelper.Style style, Array<byte> text, @NotNull() TypeDescriptor targetType)

        Auto read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "!null->!null") static JsonNode object(Array<byte> text)

        wings style read text to object, if text asXml, read as xml, otherwise as json

      • object

        @Contract(value = "_, !null -> !null") static JsonNode object(@NotNull() JacksonHelper.Style style, Array<byte> text)

        Auto read text to object, if text asXml, read as xml, otherwise as json

      • string

        @Contract(value = "!null->!null") static String string(Object obj)

        wings style serialization to json

      • string

        @Contract(value = "!null,_->!null") static String string(Object obj, boolean json)

        wings style serialization to json/xml

      • bytes

        @Contract(value = "!null->!null") static Array<byte> bytes(Object obj)

        wings style serialization to json

      • bytes

        @Contract(value = "!null,_->!null") static Array<byte> bytes(Object obj, boolean json)

        wings style serialization to json/xml

      • getBoolean

         static boolean getBoolean(JsonNode node, String field, boolean defaults)
      • getInt

         static int getInt(JsonNode node, String field, int defaults)
      • getLong

         static long getLong(JsonNode node, String field, long defaults)
      • getDouble

         static double getDouble(JsonNode node, String field, double defaults)