use of org.codehaus.jackson.map.ObjectWriter in project databus by linkedin.
the class PhysicalBuffersRequestProcessor method process.
@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
ObjectMapper mapper = new ObjectMapper();
boolean pretty = request.getParams().getProperty("pretty") != null;
// create pretty or regular writer
ObjectWriter writer = pretty ? mapper.defaultPrettyPrintingWriter() : mapper.writer();
StringWriter out = new StringWriter(10240);
DbusEventBufferMult multBuf = _relay.getEventBuffer();
Set<PhysicalPartitionKey> keys = multBuf.getAllPhysicalPartitionKeys();
// creat map to output partId=>PhysicalSources...
Map<PhysicalPartition, Set<PhysicalSource>> map = new HashMap<PhysicalPartition, Set<PhysicalSource>>(keys.size());
for (PhysicalPartitionKey key : keys) {
Set<PhysicalSource> set = multBuf.getPhysicalSourcesForPartition(key.getPhysicalPartition());
map.put(key.getPhysicalPartition(), set);
}
if (keys.isEmpty()) {
writer.writeValue(out, new HashSet<PhysicalPartition>());
} else {
writer.writeValue(out, map);
}
byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
return request;
}
use of org.codehaus.jackson.map.ObjectWriter in project ribbon by Netflix.
the class TypeTokenBasedReference method serialize.
@Override
public void serialize(OutputStream out, T object, TypeDef<?> type) throws IOException {
if (type == null) {
mapper.writeValue(out, object);
} else {
ObjectWriter writer = mapper.writerWithType(new TypeTokenBasedReference(type));
writer.writeValue(out, object);
}
}
use of org.codehaus.jackson.map.ObjectWriter in project oxCore by GluuFederation.
the class Util method asPrettyJson.
/**
* Pretty json representation of object.
*
* @param object
* object to represent
* @return json as string
* @throws IOException
*/
public static String asPrettyJson(Object object) throws IOException {
final ObjectMapper mapper = createJsonMapper().configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, false);
final ObjectWriter writer = mapper.writer().withDefaultPrettyPrinter();
return writer.writeValueAsString(object);
}
Aggregations