Class JsonToArrayMapper

java.lang.Object
net.bugreaper.modules.db.mapper.JsonToArrayMapper

public class JsonToArrayMapper extends Object
  • Method Details

    • jsonToObjectArray

      public static Object[][] jsonToObjectArray(String json, boolean addOptionsAfterValue)
      Converts a flat JSON object into a two-dimensional Object[][] array.

      Supports JSON keys with up to two options separated by ':'. The resulting row may contain 2–4 elements.

      Each JSON entry is converted into one row of the resulting array:

      • {"key": value}{"key", convertedValue}
      • {"key:OPTION": value}
        • if addOptionsAfterValue == true{"key", convertedValue, "OPTION"}
        • if addOptionsAfterValue == false{"key", "OPTION", convertedValue}

      Value conversion rules:

      Parameters:
      json - the JSON string representing a flat object
      addOptionsAfterValue - controls the order of elements when a key contains options separated by ':'. If true, the order is key, value, option. If false, the order is key, option, value.
      Returns:
      a two-dimensional Object[][] representation of the JSON object
      Throws:
      QueryBuilderException - if the provided JSON is not a flat JSON object or parsing/conversion fails