Parser
Parser to parse Google Location Timeline JSON to Kotlin objects.
This class provides efficient parsing of Google Takeout Location History data by caching JsonAdapter instances to minimize reflection overhead on repeated parsing calls.
Performance Characteristics:
JsonAdapter instances are cached and reused for optimal performance
Thread-safe: Multiple threads can safely use the same Parser instance
Memory efficient: Single Moshi instance with pre-configured adapters
Usage Recommendations:
Reuse Parser instances when parsing multiple files of the same type
Use BufferedSource overloads for better I/O performance with large files
Consider using a single Parser instance across your application
Exception Handling:
Throws JsonDataException for malformed JSON or missing required fields
Returns non-null objects; null JSON input will throw NullPointerException
Sample usages for parsing different JSON types:
val parser = Parser()
// Efficient for parsing multiple files
val bufferedSourceRecords: BufferedSource = recordsFile.source().buffer()
val records = parser.parseRecords(bufferedSourceRecords)
// Reuse the same parser instance
val bufferedSourceSemantic: BufferedSource = semanticMonthFile.source().buffer()
val semanticTimeline = parser.parseSemanticTimeline(bufferedSourceSemantic)
Functions
Parse JSON string to SemanticTimeline object.
Parse JSON buffered source to SemanticTimeline object.
Parse JSON string to TimelineEdits object.
Parse JSON buffered source to TimelineEdits object.