use of io.apicurio.datamodels.core.io.DataModelReader in project apicurio-data-models by Apicurio.
the class Library method readNode.
/**
* Call this to do a "partial read" on a given node. You must pass the JSON data for the node
* type and an empty instance of the property node class. For example, you could read just an
* Operation by passing the JSON data for the operation along with an instance of e.g.
* {@link Oas30Operation} and this will read the data and store it in the instance.
* @param json
* @param node
*/
public static Node readNode(Object json, Node node) {
// Clone the input because the reader is destructive to the source data.
Object clonedJson = JsonCompat.clone(json);
DocumentType type = node.ownerDocument().getDocumentType();
DataModelReader reader = VisitorFactory.createDataModelReader(type);
DataModelReaderDispatcher dispatcher = VisitorFactory.createDataModelReaderDispatcher(type, clonedJson, reader);
Library.visitNode(node, dispatcher);
return node;
}
use of io.apicurio.datamodels.core.io.DataModelReader in project apicurio-data-models by Apicurio.
the class Library method readDocument.
/**
* Reads an entire document from JSON data. The JSON data (already parsed, not in string format) is
* read as a data model {@link Document} and returned.
* @param json
*/
public static Document readDocument(Object json) {
// Clone the input because the reader is destructive to the source data.
Object clonedJson = JsonCompat.clone(json);
DocumentType type = discoverDocumentType(clonedJson);
DataModelReader reader = VisitorFactory.createDataModelReader(type);
Document document = DocumentFactory.create(type);
reader.readDocument(clonedJson, document);
return document;
}
Aggregations