Package org.incenp.linkml.core
Class YAMLLoader
- java.lang.Object
-
- org.incenp.linkml.core.YAMLLoader
-
public class YAMLLoader extends Object
Helper class to load or dump LinkML data instances from or to YAML files.For now this is merely a thin wrapper around both Jackson’s ObjectMapper and our own
ConverterContext.
-
-
Constructor Summary
Constructors Constructor Description YAMLLoader()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> voiddumpObject(File file, T object)Dumps a LinkML object into a YAML file.<T> voiddumpObjects(File file, List<T> objects)Dumps a list of LinkML objects into a YAML file.ConverterContextgetContext()Gets the LinkML context used by this loader.<T> TloadObject(File file, Class<T> type)Loads an instance of the specified type from a YAML file.<T> List<T>loadObjects(File file, Class<T> type)Loads a list of instances of the specified type from a YAML file.
-
-
-
Method Detail
-
getContext
public ConverterContext getContext()
Gets the LinkML context used by this loader.Client code might require access to the context (1) to customise it before loading anything (e.g. to add externally defined prefixes or set up custom converters), or (2) after loading something, to get all the prefixes that may have been found in instance data.
- Returns:
- The underlying LinkML context.
-
loadObject
public <T> T loadObject(File file, Class<T> type) throws IOException, LinkMLRuntimeException
Loads an instance of the specified type from a YAML file.- Type Parameters:
T- The type of objects to load.- Parameters:
file- The file to load the object from.type- The type of objects to load.- Returns:
- The object that was loaded.
- Throws:
IOException- If any I/O error occurs while attempting to read from the file.LinkMLRuntimeException- If the contents of the file do not match what is expected for an instance of the specified type.
-
loadObjects
public <T> List<T> loadObjects(File file, Class<T> type) throws IOException, LinkMLRuntimeException
Loads a list of instances of the specified type from a YAML file.- Type Parameters:
T- The type of objects to load.- Parameters:
file- The file to load the objects from.type- The type of objects to load.- Returns:
- The objects that were loaded.
- Throws:
IOException- If any I/O error occurs when attempting to read from the file.LinkMLRuntimeException- If the contents of the file do not match what is expected for instances of the specified type.
-
dumpObject
public <T> void dumpObject(File file, T object) throws IOException, LinkMLRuntimeException
Dumps a LinkML object into a YAML file.- Type Parameters:
T- The type of the object to dump.- Parameters:
file- The file where to dump the object.object- The object to dump.- Throws:
IOException- If any I/O error occurs when attempting to write to the file.LinkMLRuntimeException- If any error occurs when serialising the object to a raw YAML tree (this should not happen if the object is a valid LinkML object in the first place).
-
dumpObjects
public <T> void dumpObjects(File file, List<T> objects) throws IOException, LinkMLRuntimeException
Dumps a list of LinkML objects into a YAML file.- Type Parameters:
T- The type of the objects to dump. Of note, each object may be of a different subtype of that type.- Parameters:
file- The file where to dump the object.objects- The objects to dump.- Throws:
IOException- If any I/O error occurs when attempting to write to the file.LinkMLRuntimeException- If any error occurs when serialising the objects to a raw YAML tree (this should not happen if the object is a valid LinkML object in the first place).
-
-