Package com.compomics.util.io.json
Class JsonMarshaller
java.lang.Object
com.compomics.util.experiment.personalization.ExperimentObject
com.compomics.util.io.json.JsonMarshaller
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
IdentificationParametersMarshaller
,PrideMarshaller
,PTMFactoryMarshaller
public class JsonMarshaller extends ExperimentObject
This class converts non specific objects to the JSON format and vice versa.
- Author:
- Kenneth Verheggen, Marc Vaudel, Harald Barsnes
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
Constructors Constructor Description JsonMarshaller()
Default constructor.JsonMarshaller(Class... interfaces)
Constructor. -
Method Summary
Modifier and Type Method Description Object
fromJson(Class objectType, File jsonFile)
Convert from JSON to object.Object
fromJson(Class objectType, String jsonString)
Convert from JSON to object.Object
fromJson(Class objectType, URL jsonURL)
Convert from JSON to object.Object
fromJson(Type objectType, File jsonFile)
Convert from JSON to object.Object
fromJson(Type objectType, String jsonString)
Convert from JSON to object.Object
fromJson(Type objectType, URL jsonURL)
Convert from JSON to object.protected String
getJsonStringFromFile(File jsonFile)
Convert JSON string from file.protected void
init()
Initializes the marshaller with (custom) type adapters.void
saveObjectToJson(Object anObject, File jsonFile)
Save an object to JSON.String
toJson(Object anObject)
Convert an object to JSON.Methods inherited from class com.compomics.util.experiment.personalization.ExperimentObject
addUrParam, asLong, clearParametersMap, getId, getUrParam, getUrParams, removeUrParam, setId, setUrParams
-
Field Details
-
Constructor Details
-
JsonMarshaller
public JsonMarshaller()Default constructor. -
JsonMarshaller
Constructor.- Parameters:
interfaces
- comma separated list of interfaces that this class is using. They will automatically be added using a custom InterfaceAdapter.
-
-
Method Details
-
init
protected void init()Initializes the marshaller with (custom) type adapters. -
toJson
Convert an object to JSON.- Parameters:
anObject
- the input object- Returns:
- the JSON representation of an object
-
saveObjectToJson
Save an object to JSON.- Parameters:
anObject
- the input objectjsonFile
- the target file to which the JSON will be saved.- Throws:
IOException
- if the object cannot be successfully saved into a JSON file
-
fromJson
Convert from JSON to object.- Parameters:
objectType
- the class the object belongs tojsonString
- the string representation of the JSON object- Returns:
- an instance of the objectType containing the JSON information
-
fromJson
Convert from JSON to object.- Parameters:
objectType
- the class the object belongs tojsonFile
- a JSON file- Returns:
- an instance of the objectType containing the JSON information
- Throws:
IOException
- if the object cannot be successfully read from a JSON file
-
fromJson
Convert from JSON to object.- Parameters:
objectType
- the class the object belongs tojsonURL
- a JSON URL- Returns:
- an instance of the objectType containing the JSON information
- Throws:
IOException
- if the object cannot be successfully read from a JSON file
-
fromJson
Convert from JSON to object.- Parameters:
objectType
- the typetoken the object belongs tojsonString
- the string representation of the JSON object- Returns:
- an instance of the objectType containing the JSON information
-
fromJson
Convert from JSON to object.- Parameters:
objectType
- the typetoken the object belongs tojsonFile
- a JSON file- Returns:
- an instance of the objectType containing the JSON information
- Throws:
IOException
- if the object cannot be successfully read from a JSON file
-
fromJson
Convert from JSON to object.- Parameters:
objectType
- the typetoken the object belongs tojsonURL
- a JSON URL- Returns:
- an instance of the objectType containing the JSON information
- Throws:
IOException
- if the object cannot be successfully read from a JSON file
-
getJsonStringFromFile
Convert JSON string from file.- Parameters:
jsonFile
- the input JSON file- Returns:
- the string representation of the JSON content
- Throws:
FileNotFoundException
- if the JSON file can not be reachedIOException
- if the object cannot be successfully read from a JSON file
-