Class RadioReferenceJson

java.lang.Object
io.github.dsheirer.rrapi.RadioReferenceJson

public final class RadioReferenceJson extends Object
Saves and loads the library's data types as JSON, for example to cache web service results on disk between application runs. Every type returned by the service round-trips without losing values. Dates are written as ISO-8601 text. Unknown properties are ignored when reading, so a file written by a newer version of the library still loads. To check if a saved copy is current, compare its lastUpdated date (counties, agencies, trunked systems, talkgroup categories, frequencies and talkgroups) with the value the service returns now.
  • Method Details

    • toJson

      public static String toJson(Object value) throws IOException
      Converts the value to JSON
      Parameters:
      value - to convert: a data type, or a list or map of them
      Returns:
      JSON text
      Throws:
      IOException - if the value can't be converted
    • fromJson

      public static <T> T fromJson(String json, Class<T> type) throws IOException
      Reads a value from JSON
      Parameters:
      json - text
      type - of the value
      Returns:
      value
      Throws:
      IOException - if the JSON can't be read as the type
    • fromJson

      public static <T> T fromJson(String json, com.fasterxml.jackson.core.type.TypeReference<T> type) throws IOException
      Reads a generic value, e.g. a list of frequencies, from JSON
      Parameters:
      json - text
      type - of the value, e.g. new TypeReference<List<Frequency>>() {}
      Returns:
      value
      Throws:
      IOException - if the JSON can't be read as the type
    • write

      public static void write(Path path, Object value) throws IOException
      Writes the value to a JSON file. The file is replaced atomically where the file system supports it, so readers never see a partly written file.
      Parameters:
      path - of the file
      value - to write
      Throws:
      IOException - if the file can't be written
    • read

      public static <T> T read(Path path, Class<T> type) throws IOException
      Reads a value from a JSON file
      Parameters:
      path - of the file
      type - of the value
      Returns:
      value
      Throws:
      IOException - if the file can't be read as the type
    • read

      public static <T> T read(Path path, com.fasterxml.jackson.core.type.TypeReference<T> type) throws IOException
      Reads a generic value, e.g. a list of frequencies, from a JSON file
      Parameters:
      path - of the file
      type - of the value, e.g. new TypeReference<List<Frequency>>() {}
      Returns:
      value
      Throws:
      IOException - if the file can't be read as the type