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
    
    Since:

    2022-11-05

    Author:

    trydofor

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      public final static ObjectMapper JsonPlain
      public final static XmlMapper XmlPlain
    • Constructor Summary

      Constructors 
      Constructor Description
      JacksonHelper()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      static void initGlobal(ObjectMapper jsonMapper, XmlMapper xmlMapper) Init the ObjectMapper for Wings configuration
      static ObjectMapper JsonWings()
      static XmlMapper XmlWings()
      static ObjectMapper wings(boolean json)
      static <T> T object(@Nullable() String text, @NotNull() Class<T> targetType) Auto read text to object, if text asXml, read as xml, otherwise as json
      static <T> T object(@Nullable() String text, @NotNull() JavaType targetType) Auto read text to object, if text asXml, read as xml, otherwise as json
      static <T> T object(@Nullable() String text, @NotNull() TypeReference<T> targetType) Auto read text to object, if text asXml, read as xml, otherwise as json
      static JsonNode object(@Nullable() String text) Auto read text to object, if text asXml, read as xml, otherwise as json
      static boolean asXml(@Nullable() String str) whether `str` has xml characteristics, i.e.
      static String string(@Nullable() Object obj) Serialization (json) using the wings convention, output as string wherever possible to ensure data precision
      static String string(@Nullable() Object obj, boolean json) Serialization (json or xml) using the wings convention, output as string wherever possible to ensure data precision
      static String getString(JsonNode node, String field, String defaults)
      static boolean getBoolean(JsonNode node, String field, boolean defaults)
      static int getInt(JsonNode node, String field, int defaults)
      static long getLong(JsonNode node, String field, long defaults)
      static double getDouble(JsonNode node, String field, double defaults)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JacksonHelper

        JacksonHelper()
    • Method Detail

      • initGlobal

         static void initGlobal(ObjectMapper jsonMapper, XmlMapper xmlMapper)

        Init the ObjectMapper for Wings configuration

        Parameters:
        jsonMapper - handle json
        xmlMapper - handle xml
      • JsonWings

        @NotNull() static ObjectMapper JsonWings()
      • XmlWings

        @NotNull() static XmlMapper XmlWings()
      • wings

        @NotNull() static ObjectMapper wings(boolean json)
      • object

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

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

      • object

        @Contract(value = "!null,_->!null") static <T> T object(@Nullable() 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(@Nullable() String text, @NotNull() TypeReference<T> targetType)

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

      • object

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

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

      • asXml

         static boolean asXml(@Nullable() String str)

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

      • string

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

        Serialization (json) using the wings convention, output as string wherever possible to ensure data precision

      • string

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

        Serialization (json or xml) using the wings convention, output as string wherever possible to ensure data precision

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