Search in sources :

Example 1 with ObjectWriter

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ObjectWriter(org.codehaus.jackson.map.ObjectWriter) PhysicalSource(com.linkedin.databus.core.data_model.PhysicalSource) StringWriter(java.io.StringWriter) PhysicalPartitionKey(com.linkedin.databus.core.DbusEventBufferMult.PhysicalPartitionKey) DbusEventBufferMult(com.linkedin.databus.core.DbusEventBufferMult) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition)

Example 2 with ObjectWriter

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);
    }
}
Also used : ObjectWriter(org.codehaus.jackson.map.ObjectWriter)

Example 3 with ObjectWriter

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);
}
Also used : ObjectWriter(org.codehaus.jackson.map.ObjectWriter) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

ObjectWriter (org.codehaus.jackson.map.ObjectWriter)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 DbusEventBufferMult (com.linkedin.databus.core.DbusEventBufferMult)1 PhysicalPartitionKey (com.linkedin.databus.core.DbusEventBufferMult.PhysicalPartitionKey)1 PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)1 PhysicalSource (com.linkedin.databus.core.data_model.PhysicalSource)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1