use of org.codehaus.jackson.JsonGenerator in project perun by CESNET.
the class JsonSerializerGWT 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.writeStartObject();
gen.writeStringField("errorId", pex.getErrorId());
if (pex instanceof RpcException) {
gen.writeStringField("type", ((RpcException) pex).getType());
gen.writeStringField("errorInfo", ((RpcException) pex).getErrorInfo());
} else {
gen.writeStringField("type", pex.getClass().getSimpleName());
gen.writeStringField("errorInfo", pex.getMessage());
}
// write reason param for this case
if (pex instanceof ExtendMembershipException) {
gen.writeStringField("reason", ((ExtendMembershipException) pex).getReason().toString());
}
gen.writeEndObject();
}
gen.close();
}
use of org.codehaus.jackson.JsonGenerator in project perun by CESNET.
the class JsonSerializerJSONSIMPLE 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 apex-core by apache.
the class StramWebServices method init.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void init() {
//clear content type
httpResponse.setContentType(null);
if (!initialized) {
Map<Class<?>, Class<? extends StringCodec<?>>> codecs = dagManager.getApplicationAttributes().get(DAGContext.STRING_CODECS);
StringCodecs.loadConverters(codecs);
if (codecs != null) {
SimpleModule sm = new SimpleModule("DTSerializationModule", new Version(1, 0, 0, null));
for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry : codecs.entrySet()) {
try {
final StringCodec<Object> codec = (StringCodec<Object>) entry.getValue().newInstance();
sm.addSerializer(new SerializerBase(entry.getKey()) {
@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeString(codec.toString(value));
}
});
} catch (Exception ex) {
LOG.error("Caught exception when instantiating codec for class {}", entry.getKey().getName(), ex);
}
}
objectMapper.registerModule(sm);
}
initialized = true;
}
}
use of org.codehaus.jackson.JsonGenerator in project eiger by wlloyd.
the class LeveledManifest method serialize.
public synchronized void serialize() {
File manifestFile = cfs.directories.getOrCreateLeveledManifest();
File oldFile = new File(manifestFile.getPath().replace(EXTENSION, "-old.json"));
File tmpFile = new File(manifestFile.getPath().replace(EXTENSION, "-tmp.json"));
JsonFactory f = new JsonFactory();
try {
JsonGenerator g = f.createJsonGenerator(tmpFile, JsonEncoding.UTF8);
g.useDefaultPrettyPrinter();
g.writeStartObject();
g.writeArrayFieldStart("generations");
for (int level = 0; level < generations.length; level++) {
g.writeStartObject();
g.writeNumberField("generation", level);
g.writeArrayFieldStart("members");
for (SSTableReader ssTableReader : generations[level]) g.writeNumber(ssTableReader.descriptor.generation);
// members
g.writeEndArray();
// generation
g.writeEndObject();
}
// for field generations
g.writeEndArray();
// write global object
g.writeEndObject();
g.close();
if (oldFile.exists() && manifestFile.exists())
FileUtils.deleteWithConfirm(oldFile);
if (manifestFile.exists())
FileUtils.renameWithConfirm(manifestFile, oldFile);
assert tmpFile.exists();
FileUtils.renameWithConfirm(tmpFile, manifestFile);
logger.debug("Saved manifest {}", manifestFile);
} catch (IOException e) {
throw new IOError(e);
}
}
use of org.codehaus.jackson.JsonGenerator in project cassandra by apache.
the class JsonTransformer method toJson.
public static void toJson(ISSTableScanner currentScanner, Stream<UnfilteredRowIterator> partitions, boolean rawTime, TableMetadata metadata, OutputStream out) throws IOException {
try (JsonGenerator json = jsonFactory.createJsonGenerator(new OutputStreamWriter(out, StandardCharsets.UTF_8))) {
JsonTransformer transformer = new JsonTransformer(json, currentScanner, rawTime, metadata);
json.writeStartArray();
partitions.forEach(transformer::serializePartition);
json.writeEndArray();
}
}
Aggregations