use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project vespa by vespa-engine.
the class JRTServerConfigRequestV3 method addOkResponse.
@Override
public void addOkResponse(Payload payload, long generation, String configMd5) {
boolean changedConfig = !configMd5.equals(getRequestConfigMd5());
boolean changedConfigAndNewGeneration = changedConfig && ConfigUtils.isGenerationNewer(generation, getRequestGeneration());
Payload responsePayload = payload.withCompression(getCompressionType());
ByteArrayOutputStream byteArrayOutputStream = new NoCopyByteArrayOutputStream(4096);
try {
JsonGenerator jsonGenerator = createJsonGenerator(byteArrayOutputStream);
jsonGenerator.writeStartObject();
addCommonReturnValues(jsonGenerator);
setResponseField(jsonGenerator, SlimeResponseData.RESPONSE_CONFIG_MD5, configMd5);
setResponseField(jsonGenerator, SlimeResponseData.RESPONSE_CONFIG_GENERATION, generation);
jsonGenerator.writeObjectFieldStart(SlimeResponseData.RESPONSE_COMPRESSION_INFO);
if (responsePayload == null) {
throw new RuntimeException("Payload is null for ' " + this + ", not able to create response");
}
CompressionInfo compressionInfo = responsePayload.getCompressionInfo();
// If payload is not being sent, we must adjust compression info to avoid client confusion.
if (!changedConfigAndNewGeneration) {
compressionInfo = CompressionInfo.create(compressionInfo.getCompressionType(), 0);
}
compressionInfo.serialize(jsonGenerator);
jsonGenerator.writeEndObject();
if (log.isLoggable(LogLevel.SPAM)) {
log.log(LogLevel.SPAM, getConfigKey() + ": response dataXXXXX" + payload.withCompression(CompressionType.UNCOMPRESSED) + "XXXXX");
}
jsonGenerator.writeEndObject();
jsonGenerator.close();
} catch (IOException e) {
throw new IllegalArgumentException("Could not add OK response for " + this);
}
request.returnValues().add(createResponseValue(byteArrayOutputStream));
if (changedConfigAndNewGeneration) {
request.returnValues().add(new DataValue(responsePayload.getData().getBytes()));
} else {
request.returnValues().add(new DataValue(new byte[0]));
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project vespa by vespa-engine.
the class AccessLogRequestHandler method handle.
@Override
public HttpResponse handle(HttpRequest request) {
final List<String> uris = circularArrayAccessLogKeeper.getUris();
return new HttpResponse(200) {
@Override
public void render(OutputStream outputStream) throws IOException {
JsonGenerator generator = jsonFactory.createGenerator(outputStream);
generator.writeStartObject();
generator.writeArrayFieldStart("entries");
for (String uri : uris) {
generator.writeStartObject();
generator.writeStringField("url", uri);
generator.writeEndObject();
}
generator.writeEndArray();
generator.writeEndObject();
generator.close();
}
};
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project endpoints-java by cloudendpoints.
the class ServletResponseResultWriter method getWriteDateAndTimeAsStringModule.
private static SimpleModule getWriteDateAndTimeAsStringModule() {
JsonSerializer<DateAndTime> dateAndTimeSerializer = new JsonSerializer<DateAndTime>() {
@Override
public void serialize(DateAndTime value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeString(value.toRfc3339String());
}
};
SimpleModule writeDateAsStringModule = new SimpleModule("writeDateAsStringModule", new Version(1, 0, 0, null, null, null));
writeDateAsStringModule.addSerializer(DateAndTime.class, dateAndTimeSerializer);
return writeDateAsStringModule;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project walkmod-core by walkmod.
the class YAMLConfigurationProvider method write.
public void write(JsonNode node) throws TransformerException {
if (node != null) {
File cfg = new File(fileName);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(cfg);
JsonGenerator generator = mapper.getFactory().createGenerator(fos);
generator.useDefaultPrettyPrinter();
mapper.writeTree(generator, node);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
throw new TransformerException("Error writting the configuration", e);
}
}
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project kripton by xcesco.
the class DaoBean05Impl method serializer1.
/**
* for param serializer1 serialization
*/
private byte[] serializer1(Long value) {
if (value == null) {
return null;
}
KriptonJsonContext context = KriptonBinder.jsonBind();
try (KriptonByteArrayOutputStream stream = new KriptonByteArrayOutputStream();
JacksonWrapperSerializer wrapper = context.createSerializer(stream)) {
JsonGenerator jacksonSerializer = wrapper.jacksonGenerator;
int fieldCount = 0;
jacksonSerializer.writeStartObject();
if (value != null) {
jacksonSerializer.writeNumberField("element", value);
}
jacksonSerializer.writeEndObject();
jacksonSerializer.flush();
return stream.toByteArray();
} catch (Exception e) {
throw (new KriptonRuntimeException(e.getMessage()));
}
}
Aggregations