Search in sources :

Example 1 with JsonIo

use of org.sbolstandard.core.io.json.JsonIo in project libSBOLj by SynBioDex.

the class SBOLReader method readJSON.

/**
 * @param stream
 * @return
 * @throws SBOLValidationException if the following SBOL validation rule was violated: 10105.
 */
private static DocumentRoot<QName> readJSON(Reader stream) throws SBOLValidationException {
    JsonReader reader = Json.createReaderFactory(Collections.<String, Object>emptyMap()).createReader(stream);
    JsonIo jsonIo = new JsonIo();
    IoReader<String> ioReader = jsonIo.createIoReader(reader.read());
    DocumentRoot<String> root;
    try {
        root = ioReader.read();
    } catch (CoreIoException e) {
        throw new SBOLValidationException("sbol-10105", e);
    }
    return StringifyQName.string2qname.mapDR(root);
}
Also used : JsonIo(org.sbolstandard.core.io.json.JsonIo) JsonReader(javax.json.JsonReader) CoreIoException(org.sbolstandard.core.io.CoreIoException)

Example 2 with JsonIo

use of org.sbolstandard.core.io.json.JsonIo in project libSBOLj by SynBioDex.

the class SBOLWriter method writeJSON.

private static void writeJSON(Writer stream, DocumentRoot<QName> document) throws CoreIoException {
    HashMap<String, Object> config = new HashMap<>();
    config.put(JsonGenerator.PRETTY_PRINTING, true);
    JsonGenerator writer = Json.createGeneratorFactory(config).createGenerator(stream);
    JsonIo jsonIo = new JsonIo();
    jsonIo.createIoWriter(writer).write(StringifyQName.qname2string.mapDR(document));
    writer.flush();
    writer.close();
}
Also used : JsonIo(org.sbolstandard.core.io.json.JsonIo) HashMap(java.util.HashMap) JsonGenerator(javax.json.stream.JsonGenerator)

Aggregations

JsonIo (org.sbolstandard.core.io.json.JsonIo)2 HashMap (java.util.HashMap)1 JsonReader (javax.json.JsonReader)1 JsonGenerator (javax.json.stream.JsonGenerator)1 CoreIoException (org.sbolstandard.core.io.CoreIoException)1