use of javax.json.JsonWriterFactory in project dataverse by IQSS.
the class AbstractApiBeanTest method testMessagesNoJsonObject.
@Test
public void testMessagesNoJsonObject() {
String message = "myMessage";
Response response = sut.ok(message);
JsonReader jsonReader = Json.createReader(new StringReader((String) response.getEntity().toString()));
JsonObject jsonObject = jsonReader.readObject();
Map<String, Boolean> config = new HashMap<>();
config.put(JsonGenerator.PRETTY_PRINTING, true);
JsonWriterFactory jwf = Json.createWriterFactory(config);
StringWriter sw = new StringWriter();
try (JsonWriter jsonWriter = jwf.createWriter(sw)) {
jsonWriter.writeObject(jsonObject);
}
logger.info(sw.toString());
assertEquals(message, jsonObject.getJsonObject("data").getString("message"));
}
use of javax.json.JsonWriterFactory in project iaf by ibissource.
the class Misc method jsonPretty.
public static String jsonPretty(String json) {
StringWriter sw = new StringWriter();
JsonReader jr = Json.createReader(new StringReader(json));
JsonObject jobj = jr.readObject();
Map<String, Object> properties = new HashMap<>(1);
properties.put(JsonGenerator.PRETTY_PRINTING, true);
JsonWriterFactory writerFactory = Json.createWriterFactory(properties);
try (JsonWriter jsonWriter = writerFactory.createWriter(sw)) {
jsonWriter.writeObject(jobj);
}
return sw.toString().trim();
}
Aggregations