Class DataFormatter


  • public class DataFormatter
    extends Object
    This class can format maps, lists and primitives (boolean, number, string). The output can be use human-friendly formatting with new lines and indentation. And the output can be JSON or it can use Java toString(). If the output should be JSON, any object that is not a map, list or primitive, will be converted to a map first.
    • Constructor Detail

      • DataFormatter

        public DataFormatter()
    • Method Detail

      • format

        public String format​(Object value,
                             boolean human)
        Returns a string representation of the specified value (map, list or primitive). If "human" is true, the returned string will have a friendly formatting, possibly spanning multiple lines.

        The output of primitives will use Java toString(). See also format(value, human, json).

        Parameters:
        value - the value to format
        human - true for friendly formatting, false for single-line formatting
        Returns:
        the string
      • format

        public String format​(Object value,
                             boolean human,
                             boolean json)
        Returns a string representation of the specified value (map, list or primitive). If "human" is true, the returned string will have a friendly formatting, possibly spanning multiple lines.
        Parameters:
        value - the value to format
        human - true for friendly formatting, false for single-line formatting
        json - true if the output should be JSON, false if the output should use Java toString()
        Returns:
        the string