Search in sources :

Example 1 with DataModelReaderDispatcher

use of io.apicurio.datamodels.core.io.DataModelReaderDispatcher 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;
}
Also used : DocumentType(io.apicurio.datamodels.core.models.DocumentType) DataModelReaderDispatcher(io.apicurio.datamodels.core.io.DataModelReaderDispatcher) DataModelReader(io.apicurio.datamodels.core.io.DataModelReader)

Aggregations

DataModelReader (io.apicurio.datamodels.core.io.DataModelReader)1 DataModelReaderDispatcher (io.apicurio.datamodels.core.io.DataModelReaderDispatcher)1 DocumentType (io.apicurio.datamodels.core.models.DocumentType)1