Package qupath.lib.io

Class GsonTools.SubTypeAdapterFactory<T>

java.lang.Object
qupath.lib.io.GsonTools.SubTypeAdapterFactory<T>
Type Parameters:
T -
All Implemented Interfaces:
TypeAdapterFactory
Enclosing class:
GsonTools

public static class GsonTools.SubTypeAdapterFactory<T> extends Object implements TypeAdapterFactory
A TypeAdapterFactory that is suitable for handling class hierarchies. This can be used to construct the appropriate subtype when parsing the JSON.

This is inspired and influenced by the RuntimeTypeAdapterFactory class available as part of Gson extras, but not the main Gson library (https://github.com/google/gson/blob/gson-parent-2.8.6/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java), which is Copyright (C) 2011 Google Inc. licensed under Apache License, Version 2.0.

This behavior of this class differs in several ways:

  • it supports alias labels for deserialization, which can be used to help achieve backwards compatibility
  • it avoids use of the internal Streams class for Gson, which complicates modularity
  • it does not support a maintainLabel option (the label field is always removed)