Class RadioReferenceJson
java.lang.Object
io.github.dsheirer.rrapi.RadioReferenceJson
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 Summary
Modifier and TypeMethodDescriptionstatic <T> TReads a generic value, e.g.static <T> TReads a value from JSONstatic <T> TReads a generic value, e.g.static <T> TReads a value from a JSON filestatic StringConverts the value to JSONstatic voidWrites the value to a JSON file.
-
Method Details
-
toJson
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
Reads a value from JSON- Parameters:
json- texttype- 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- texttype- of the value, e.g. new TypeReference<List<Frequency>>() {}- Returns:
- value
- Throws:
IOException- if the JSON can't be read as the type
-
write
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 filevalue- to write- Throws:
IOException- if the file can't be written
-
read
Reads a value from a JSON file- Parameters:
path- of the filetype- 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 filetype- of the value, e.g. new TypeReference<List<Frequency>>() {}- Returns:
- value
- Throws:
IOException- if the file can't be read as the type
-