use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project retrofit by square.
the class JacksonConverterFactory method requestBodyConverter.
@Override
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
JavaType javaType = mapper.getTypeFactory().constructType(type);
ObjectWriter writer = mapper.writerFor(javaType);
return new JacksonRequestBodyConverter<>(writer);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project spring-framework by spring-projects.
the class Jackson2JsonEncoder method encodeValue.
private DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory, ResolvableType type, Map<String, Object> hints) {
TypeFactory typeFactory = this.mapper.getTypeFactory();
JavaType javaType = typeFactory.constructType(type.getType());
if (type.isInstance(value)) {
javaType = getJavaType(type.getType(), null);
}
ObjectWriter writer;
Class<?> jsonView = (Class<?>) hints.get(AbstractJackson2Codec.JSON_VIEW_HINT);
if (jsonView != null) {
writer = this.mapper.writerWithView(jsonView);
} else {
writer = this.mapper.writer();
}
if (javaType != null && javaType.isContainerType()) {
writer = writer.forType(javaType);
}
Boolean sse = (Boolean) hints.get(ServerSentEventHttpMessageWriter.SSE_CONTENT_HINT);
SerializationConfig config = writer.getConfig();
if (Boolean.TRUE.equals(sse) && config.isEnabled(SerializationFeature.INDENT_OUTPUT)) {
writer = writer.with(this.ssePrettyPrinter);
}
DataBuffer buffer = bufferFactory.allocateBuffer();
OutputStream outputStream = buffer.asOutputStream();
try {
writer.writeValue(outputStream, value);
} catch (IOException ex) {
throw new CodecException("Error while writing the data", ex);
}
return buffer;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project pinpoint by naver.
the class PluginDisableIT method test.
@Test
public void test() throws Exception {
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "jackson");
mapper.writeValueAsString(map);
mapper.writeValueAsBytes(map);
ObjectWriter writer = mapper.writer();
writer.writeValueAsString(map);
writer.writeValueAsBytes(map);
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
verifier.verifyTraceCount(0);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project pulsar by yahoo.
the class PerformanceConsumer method main.
public static void main(String[] args) throws Exception {
final Arguments arguments = new Arguments();
JCommander jc = new JCommander(arguments);
jc.setProgramName("pulsar-perf-consumer");
try {
jc.parse(args);
} catch (ParameterException e) {
System.out.println(e.getMessage());
jc.usage();
System.exit(-1);
}
if (arguments.help) {
jc.usage();
System.exit(-1);
}
if (arguments.topic.size() != 1) {
System.out.println("Only one destination name is allowed");
jc.usage();
System.exit(-1);
}
if (arguments.confFile != null) {
Properties prop = new Properties(System.getProperties());
prop.load(new FileInputStream(arguments.confFile));
if (arguments.serviceURL == null) {
arguments.serviceURL = prop.getProperty("brokerServiceUrl");
}
if (arguments.serviceURL == null) {
arguments.serviceURL = prop.getProperty("webServiceUrl");
}
// fallback to previous-version serviceUrl property to maintain backward-compatibility
if (arguments.serviceURL == null) {
arguments.serviceURL = prop.getProperty("serviceUrl", "http://localhost:8080/");
}
if (arguments.authPluginClassName == null) {
arguments.authPluginClassName = prop.getProperty("authPlugin", null);
}
if (arguments.authParams == null) {
arguments.authParams = prop.getProperty("authParams", null);
}
}
// Dump config variables
ObjectMapper m = new ObjectMapper();
ObjectWriter w = m.writerWithDefaultPrettyPrinter();
log.info("Starting Pulsar performance consumer with config: {}", w.writeValueAsString(arguments));
final DestinationName prefixDestinationName = DestinationName.get(arguments.topic.get(0));
final RateLimiter limiter = arguments.rate > 0 ? RateLimiter.create(arguments.rate) : null;
MessageListener listener = new MessageListener() {
public void received(Consumer consumer, Message msg) {
messagesReceived.increment();
bytesReceived.add(msg.getData().length);
if (limiter != null) {
limiter.acquire();
}
consumer.acknowledgeAsync(msg);
}
};
EventLoopGroup eventLoopGroup;
if (SystemUtils.IS_OS_LINUX) {
eventLoopGroup = new EpollEventLoopGroup(Runtime.getRuntime().availableProcessors() * 2, new DefaultThreadFactory("pulsar-perf-consumer"));
} else {
eventLoopGroup = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors(), new DefaultThreadFactory("pulsar-perf-consumer"));
}
ClientConfiguration clientConf = new ClientConfiguration();
clientConf.setConnectionsPerBroker(arguments.maxConnections);
clientConf.setStatsInterval(arguments.statsIntervalSeconds, TimeUnit.SECONDS);
if (isNotBlank(arguments.authPluginClassName)) {
clientConf.setAuthentication(arguments.authPluginClassName, arguments.authParams);
}
PulsarClient pulsarClient = new PulsarClientImpl(arguments.serviceURL, clientConf, eventLoopGroup);
List<Future<Consumer>> futures = Lists.newArrayList();
ConsumerConfiguration consumerConfig = new ConsumerConfiguration();
consumerConfig.setMessageListener(listener);
consumerConfig.setReceiverQueueSize(arguments.receiverQueueSize);
for (int i = 0; i < arguments.numDestinations; i++) {
final DestinationName destinationName = (arguments.numDestinations == 1) ? prefixDestinationName : DestinationName.get(String.format("%s-%d", prefixDestinationName, i));
log.info("Adding {} consumers on destination {}", arguments.numConsumers, destinationName);
for (int j = 0; j < arguments.numConsumers; j++) {
String subscriberName;
if (arguments.numConsumers > 1) {
subscriberName = String.format("%s-%d", arguments.subscriberName, j);
} else {
subscriberName = arguments.subscriberName;
}
futures.add(pulsarClient.subscribeAsync(destinationName.toString(), subscriberName, consumerConfig));
}
}
for (Future<Consumer> future : futures) {
future.get();
}
log.info("Start receiving from {} consumers on {} destinations", arguments.numConsumers, arguments.numDestinations);
long oldTime = System.nanoTime();
while (true) {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
break;
}
long now = System.nanoTime();
double elapsed = (now - oldTime) / 1e9;
double rate = messagesReceived.sumThenReset() / elapsed;
double throughput = bytesReceived.sumThenReset() / elapsed * 8 / 1024 / 1024;
log.info("Throughput received: {} msg/s -- {} Mbit/s", dec.format(rate), dec.format(throughput));
oldTime = now;
}
pulsarClient.close();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project camel by apache.
the class SObjectTreeTest method shouldSerializeToJson.
@Test
public void shouldSerializeToJson() throws JsonProcessingException {
final ObjectMapper mapper = new ObjectMapper();
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
final ObjectWriter writer = mapper.writerFor(SObjectTree.class);
final SObjectTree tree = new SObjectTree();
final SObjectNode account1 = new SObjectNode(tree, simpleAccount);
account1.addChild("Contacts", smith);
account1.addChild("Contacts", evans);
tree.addNode(account1);
final SObjectNode account2 = new SObjectNode(tree, simpleAccount2);
tree.addNode(account2);
final String json = writer.writeValueAsString(tree);
assertEquals("Should serialize to JSON as in Salesforce example", //
"{\"records\":[" + //
"{" + //
"\"attributes\":{\"referenceId\":\"ref1\",\"type\":\"Account\"}," + //
"\"Industry\":\"Banking\"," + //
"\"Name\":\"SampleAccount\"," + //
"\"NumberOfEmployees\":100," + //
"\"Phone\":\"1234567890\"," + //
"\"Website\":\"www.salesforce.com\"," + //
"\"Contacts\":{" + //
"\"records\":[" + //
"{" + //
"\"attributes\":{\"referenceId\":\"ref2\",\"type\":\"Contact\"}," + //
"\"Email\":\"sample@salesforce.com\"," + //
"\"LastName\":\"Smith\"," + //
"\"Title\":\"President\"" + //
"}," + //
"{" + //
"\"attributes\":{\"referenceId\":\"ref3\",\"type\":\"Contact\"}," + //
"\"Email\":\"sample@salesforce.com\"," + //
"\"LastName\":\"Evans\"," + //
"\"Title\":\"Vice President\"" + //
"}" + //
"]" + //
"}" + //
"}," + //
"{" + //
"\"attributes\":{\"referenceId\":\"ref4\",\"type\":\"Account\"}," + //
"\"Industry\":\"Banking\"," + //
"\"Name\":\"SampleAccount2\"," + //
"\"NumberOfEmployees\":100," + //
"\"Phone\":\"1234567890\"," + //
"\"Website\":\"www.salesforce2.com\"" + //
"}" + //
"]" + "}", json);
}
Aggregations