Class JsonSerializerUtils


  • public class JsonSerializerUtils
    extends Object
    Provides a utility class for rendering JobDef, StepDef and ActionDef to build JSON output.
    Since:
    4.0.0
    • Method Detail

      • renderJsonObject

        public static void renderJsonObject​(StringBuilder builder,
                                            Map jsonObjectMap,
                                            int padSpaces,
                                            boolean layoutSameLine,
                                            String[] attributeOrderArrray)
        Adds a string representation of a JSON object to a string builder. This only supports JSON object which have attribute values that are strings.
        Parameters:
        builder - the String Builder that has the string value appended to.
        jsonObjectMap - a Map that holds the JSON object.
        padSpaces - an integer representing the left padding associated with used if not on the same line
        layoutSameLine - boolean if true the JSON string will appear on the same line.
        attributeOrderArrray - String[] contains a array of Attribute names in the order to appear in the JSON
      • renderJsonArray

        public static void renderJsonArray​(StringBuilder builder,
                                           List listJsonArray,
                                           int padSpaces,
                                           boolean itemSameLine,
                                           String[] itemAttributeOrderArrray)
        Adds a string representation of a JSON Array to a string builder. This assumes Each array item contains an JSON Object.
        Parameters:
        builder - the String Builder that has the string value appended to.
        listJsonArray - List containing the data to be converted to a JSON Array.
        padSpaces - an integer representing the left padding associated with used if not on the same line.
        itemSameLine - boolean if set to true will render each item on the same line
        itemAttributeOrderArrray - String[] contains a list of String Attribute names in the order to appear in the JSON Object Items
      • renderAttribute

        public static void renderAttribute​(StringBuilder builder,
                                           String attName,
                                           Object jsonObj,
                                           int padSpaces,
                                           boolean isFirst,
                                           boolean layoutValueSameLine,
                                           String[] subFieldOrder)
        Renders a string representation of a JSON Attribute name and value
        Parameters:
        builder - the String Builder that has the string value appended to.
        attName - this the JSON attribute name
        jsonObj - this is the attribute value
        padSpaces - this is the attribute spacing
        isFirst - boolean if set treats this a the first element. It constructs the first "{" or "["
        layoutValueSameLine - boolean this is passed to either the renderJsonArray or renderJsonObject.
        subFieldOrder - String[] JSON objects attributes will be sorted in this name order, if null then attributes will be ordered by name alphabetically.
      • convertMap2JSONList

        public static List<Map<String,​String>> convertMap2JSONList​(Map<String,​String> map2Convert,
                                                                         String keyName,
                                                                         String valueName)
        Converts a map that holds pair value such as the routeMap to a List<map<String,String>> which can be used to generate a JSON Array.
        Parameters:
        map2Convert - Map<String,Stringg> that holds the pair value.
        keyName - the JSON attribute String name for the key
        valueName - The JSON attribute String name for the value
        Returns:
        List<map<String,String>> the converted List that can be passed to renderJsonArray