use of org.codehaus.jackson.JsonGenerator in project stargate-core by tuplejump.
the class Group method toByteBuffer.
public ByteBuffer toByteBuffer() throws IOException {
BufferRecycler bufferRecycler = bufferThreadLocal.get();
ByteArrayBuilder bytes = new ByteArrayBuilder(bufferRecycler);
IOContext ioContext = new IOContext(bufferRecycler, bytes, false);
JsonGenerator gen = new Utf8Generator(ioContext, 0, null, bytes);
gen.enable(JsonGenerator.Feature.QUOTE_FIELD_NAMES);
gen.enable(JsonGenerator.Feature.QUOTE_NON_NUMERIC_NUMBERS);
gen.enable(JsonGenerator.Feature.ESCAPE_NON_ASCII);
writeJson(gen);
gen.flush();
bytes.flush();
bytes.close();
return ByteBuffer.wrap(bytes.toByteArray());
}
use of org.codehaus.jackson.JsonGenerator in project YCSB by brianfrankcooper.
the class MemcachedClient method toJson.
protected static String toJson(Map<String, ByteIterator> values) throws IOException {
ObjectNode node = MAPPER.createObjectNode();
HashMap<String, String> stringMap = StringByteIterator.getStringMap(values);
for (Map.Entry<String, String> pair : stringMap.entrySet()) {
node.put(pair.getKey(), pair.getValue());
}
JsonFactory jsonFactory = new JsonFactory();
Writer writer = new StringWriter();
JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer);
MAPPER.writeTree(jsonGenerator, node);
return writer.toString();
}
use of org.codehaus.jackson.JsonGenerator in project perun by CESNET.
the class JsonSerializer method writePerunException.
@Override
public void writePerunException(PerunException pex) throws IOException {
JsonGenerator gen = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
if (pex == null) {
throw new IllegalArgumentException("pex is null");
} else {
gen.writeObject(pex);
gen.flush();
}
gen.close();
}
use of org.codehaus.jackson.JsonGenerator in project perun by CESNET.
the class JsonSerializer method write.
@Override
public void write(Object object) throws RpcException, IOException {
JsonGenerator gen = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
try {
gen.writeObject(object);
gen.flush();
gen.close();
} catch (JsonProcessingException ex) {
throw new RpcException(RpcException.Type.CANNOT_SERIALIZE_VALUE, ex);
}
}
use of org.codehaus.jackson.JsonGenerator in project perun by CESNET.
the class JsonSerializer method write.
@Override
public void write(Object object) throws RpcException, IOException {
JsonGenerator gen = jsonFactory.createJsonGenerator(out, JsonEncoding.UTF8);
if (object instanceof Throwable) {
throw new IllegalArgumentException("Tried to serialize a throwable object using write()", (Throwable) object);
}
try {
gen.writeObject(object);
gen.close();
} catch (JsonProcessingException ex) {
throw new RpcException(RpcException.Type.CANNOT_SERIALIZE_VALUE, ex);
}
}
Aggregations