use of com.fasterxml.jackson.core.PrettyPrinter in project jackson-core by FasterXML.
the class TestJDKSerializability method testPrettyPrinter.
public void testPrettyPrinter() throws Exception {
PrettyPrinter p = new DefaultPrettyPrinter();
byte[] stuff = jdkSerialize(p);
PrettyPrinter back = jdkDeserialize(stuff);
// what should we test?
assertNotNull(back);
}
use of com.fasterxml.jackson.core.PrettyPrinter in project asterixdb by apache.
the class ResultExtractor method extract.
public static InputStream extract(InputStream resultStream) throws Exception {
ObjectMapper om = new ObjectMapper();
String resultStr = IOUtils.toString(resultStream, Charset.defaultCharset());
PrettyPrinter singleLine = new SingleLinePrettyPrinter();
ObjectNode result = om.readValue(resultStr, ObjectNode.class);
LOGGER.fine("+++++++\n" + result + "\n+++++++\n");
String type = "";
String status = "";
String results = "";
String field = "";
for (Iterator<String> sIter = result.fieldNames(); sIter.hasNext(); ) {
field = sIter.next();
switch(field) {
case "requestID":
break;
case "clientContextID":
break;
case "signature":
break;
case "status":
status = om.writeValueAsString(result.get(field));
break;
case "type":
type = om.writeValueAsString(result.get(field));
break;
case "metrics":
LOGGER.fine(om.writeValueAsString(result.get(field)));
break;
case "errors":
JsonNode errors = result.get(field).get(0).get("msg");
throw new AsterixException(errors.asText());
case "results":
if (result.get(field).size() <= 1) {
if (result.get(field).size() == 0) {
results = "";
} else if (result.get(field).isArray()) {
if (result.get(field).get(0).isTextual()) {
results = result.get(field).get(0).asText();
} else {
ObjectMapper omm = new ObjectMapper();
omm.setDefaultPrettyPrinter(singleLine);
omm.enable(SerializationFeature.INDENT_OUTPUT);
results = omm.writer(singleLine).writeValueAsString(result.get(field));
}
} else {
results = om.writeValueAsString(result.get(field));
}
} else {
StringBuilder sb = new StringBuilder();
JsonNode[] fields = Iterators.toArray(result.get(field).elements(), JsonNode.class);
if (fields.length > 1) {
for (JsonNode f : fields) {
if (f.isObject()) {
sb.append(om.writeValueAsString(f));
} else {
sb.append(f.asText());
}
}
}
results = sb.toString();
}
break;
default:
throw new AsterixException("Unanticipated field \"" + field + "\"");
}
}
return IOUtils.toInputStream(results);
}
Aggregations