Class ReportJsonUtils


  • public class ReportJsonUtils
    extends Object
    For converting reports to JSON and vice versa.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • ReportJsonUtils

        public ReportJsonUtils()
    • Method Detail

      • example

        public static String example()
        Returns an example report in JSON.
        Returns:
        the example string
      • fromJson

        public static Report fromJson​(Reader reader)
                               throws Exception
        Creates a report from the reader, reading in JSON.
        Parameters:
        reader - the reader to obtain the JSON from
        Returns:
        the report, null if failed to create or find data
        Throws:
        Exception - if reading/parsing fails
      • fromJson

        public static Report fromJson​(Reader reader,
                                      String prefix)
                               throws Exception
        Creates a report from the reader, reading in JSON.
        Parameters:
        reader - the reader to obtain the JSON from
        prefix - the prefix to use for the fields, ignored if null
        Returns:
        the report, null if failed to create or find data
        Throws:
        Exception - if reading/parsing fails
      • fromJson

        public static Report fromJson​(com.google.gson.JsonObject jobj)
        Creates a report from the JSON object.
        Parameters:
        jobj - the object to get the data from
        Returns:
        the report, null if failed to create or find data
      • fromJson

        public static Report fromJson​(com.google.gson.JsonObject jobj,
                                      String prefix)
        Creates a report from the JSON object.
        Parameters:
        jobj - the object to get the data from
        prefix - the prefix to use for the fields, ignored if null
        Returns:
        the report, null if failed to create or find data
      • toJson

        public static com.google.gson.JsonObject toJson​(Report report)
        Turns the report into a json structure.
        Parameters:
        report - the report to convert
        Returns:
        the json data structure
      • toJson

        public static com.google.gson.JsonObject toJson​(Report report,
                                                        Field[] fields)
        Turns the specified fields from the report into a json structure.
        Parameters:
        report - the report to convert
        fields - the fields to limit it to, leave empty to use all fields
        Returns:
        the json data structure