use of javax.json.JsonReader in project dataverse by IQSS.
the class SchemaDotOrgExporter method exportDataset.
@Override
public void exportDataset(DatasetVersion version, JsonObject json, OutputStream outputStream) throws ExportException {
String jsonLdAsString = version.getJsonLd();
StringReader stringReader = new StringReader(jsonLdAsString);
JsonReader jsonReader = Json.createReader(stringReader);
JsonObject jsonLdJsonObject = jsonReader.readObject();
try {
outputStream.write(jsonLdJsonObject.toString().getBytes("UTF8"));
} catch (IOException ex) {
logger.info("IOException calling outputStream.write: " + ex);
}
try {
outputStream.flush();
} catch (IOException ex) {
logger.info("IOException calling outputStream.flush: " + ex);
}
}
use of javax.json.JsonReader in project javaee7-samples by javaee-samples.
the class JsonReaderFromReaderTest method testArray.
@Test
public void testArray() throws JSONException {
JsonReader jsonReader = Json.createReader(new StringReader("[" + " { \"apple\":\"red\" }," + " { \"banana\":\"yellow\" }" + "]"));
JsonArray jsonArr = jsonReader.readArray();
assertNotNull(jsonArr);
assertEquals(2, jsonArr.size());
JSONAssert.assertEquals("{\"apple\":\"red\"}", jsonArr.get(0).toString(), JSONCompareMode.STRICT);
JSONAssert.assertEquals("{\"banana\":\"yellow\"}", jsonArr.get(1).toString(), JSONCompareMode.STRICT);
}
use of javax.json.JsonReader in project javaee7-samples by javaee-samples.
the class JsonReaderFromReaderTest method testEmptyObject.
@Test
public void testEmptyObject() throws JSONException {
JsonReader jsonReader = Json.createReader(new StringReader("{}"));
JsonObject json = jsonReader.readObject();
assertNotNull(json);
assertTrue(json.isEmpty());
}
use of javax.json.JsonReader in project javaee7-samples by javaee-samples.
the class JsonReaderFromReaderTest method testSimpleObjectWithTwoElements.
@Test
public void testSimpleObjectWithTwoElements() throws JSONException {
JsonReader jsonReader = Json.createReader(new StringReader("{" + " \"apple\":\"red\"," + " \"banana\":\"yellow\"" + "}"));
JsonObject json = jsonReader.readObject();
assertNotNull(json);
assertFalse(json.isEmpty());
assertTrue(json.containsKey("apple"));
assertEquals("red", json.getString("apple"));
assertTrue(json.containsKey("banana"));
assertEquals("yellow", json.getString("banana"));
}
use of javax.json.JsonReader in project javaee7-samples by javaee-samples.
the class JsonReaderFromStreamTest method testArray.
@Test
public void testArray() throws JSONException {
JsonReader jsonReader = Json.createReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("/3.json"));
JsonArray jsonArr = jsonReader.readArray();
assertNotNull(jsonArr);
assertEquals(2, jsonArr.size());
JSONAssert.assertEquals("{\"apple\":\"red\"}", jsonArr.get(0).toString(), JSONCompareMode.STRICT);
JSONAssert.assertEquals("{\"banana\":\"yellow\"}", jsonArr.get(1).toString(), JSONCompareMode.STRICT);
}
Aggregations