Package qupath.lib.io
Class GsonTools
java.lang.Object
qupath.lib.io.GsonTools
Helper class providing Gson instances with type adapters registered to serialize 
 several key classes.
 
These include:
- PathObject
- PathClass
- ROI
- ImagePlane
- Java Topology Suite Geometry objects
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classATypeAdapterFactorythat is suitable for handling class hierarchies.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic <T> GsonTools.SubTypeAdapterFactory<T> createSubTypeAdapterFactory(Class<T> baseType, String typeFieldName) Create aTypeAdapterFactorythat is suitable for handling class hierarchies.static GsonBuilderAccess the builder used withgetInstance().static GsonGet default Gson instance, capable of serializing/deserializing some key QuPath classes.static GsongetInstance(boolean pretty) Get default Gson, optionally with pretty printing enabled.static GsonGet Gson instance capable of serializing/deserializing some key QuPath classes, and configured for pretty printing.static List<PathObject> parseObjectsFromGeoJSON(JsonElement element) Attempt to read PathObjects from a JsonElement, interpreting it as GeoJSON.static List<PathObject> Attempt to read PathObjects from a JSON string, interpreting it as GeoJSON.
- 
Constructor Details- 
GsonToolspublic GsonTools()
 
- 
- 
Method Details- 
getDefaultBuilderAccess the builder used withgetInstance(). This makes it possible to register new type adapters if required, which will be used by future Gson instances returned by this class.Use this with caution! Changes made here impact JSON serialization/deserialization throughout the software. Access by be removed or restricted in the future for this reason. To create a derived builder that inherits from the default but does not change it, use GsonBuilder.getInstance().newBuilder().- Returns:
 
- 
createSubTypeAdapterFactorypublic static <T> GsonTools.SubTypeAdapterFactory<T> createSubTypeAdapterFactory(Class<T> baseType, String typeFieldName) Create aTypeAdapterFactorythat is suitable for handling class hierarchies. This can be used to construct the appropriate subtype when parsing the JSON by using a specific field in the JSON representation.- Type Parameters:
- T-
- Parameters:
- baseType- the base type, i.e. the class or interface that all types descend from
- typeFieldName- a field name to include within the serialized JSON object to identify the specific type
- Returns:
 
- 
getInstanceGet default Gson instance, capable of serializing/deserializing some key QuPath classes.- Returns:
- See Also:
 
- 
getPrettyPrintInstanceGet Gson instance capable of serializing/deserializing some key QuPath classes, and configured for pretty printing.- Returns:
- Since:
- v0.6.0
- See Also:
 
- 
getInstanceGet default Gson, optionally with pretty printing enabled.- Parameters:
- pretty- if true, write using pretty-printing (i.e. more whitespace for formatting)
- Returns:
- See Also:
 
- 
parseObjectsFromGeoJSONpublic static List<PathObject> parseObjectsFromGeoJSON(JsonElement element) throws JsonParseException Attempt to read PathObjects from a JsonElement, interpreting it as GeoJSON.This deals with the fact that objects can be stored in different forms: as a Feature, FeatureCollection, or array of Features. This method can be provided with other JsonElements, and provided they do not contain characteristic GeoJSON fields (i.e. a "type" of "Feature", "FeatureCollection", or a "Geometry" subtype), they will be ignored. - Parameters:
- element-
- Returns:
- a list of objects read from the element, or an empty list if none could be found
- Throws:
- JsonParseException
- Since:
- v0.5.0
- See Also:
 
- 
parseObjectsFromGeoJSONAttempt to read PathObjects from a JSON string, interpreting it as GeoJSON.- Parameters:
- json- the JSON string
- Returns:
- a list of objects read from the element, or an empty list if none could be found
- Throws:
- JsonParseException
- Since:
- v0.6.0
- See Also:
 
 
-