use of com.fasterxml.jackson.databind.ObjectMapper in project flink by apache.
the class WebFrontendITCase method getTaskmanagers.
@Test
public void getTaskmanagers() {
try {
String json = getFromHTTP("http://localhost:" + port + "/taskmanagers/");
ObjectMapper mapper = new ObjectMapper();
JsonNode parsed = mapper.readTree(json);
ArrayNode taskManagers = (ArrayNode) parsed.get("taskmanagers");
assertNotNull(taskManagers);
assertEquals(cluster.numTaskManagers(), taskManagers.size());
JsonNode taskManager = taskManagers.get(0);
assertNotNull(taskManager);
assertEquals(NUM_SLOTS, taskManager.get("slotsNumber").asInt());
assertTrue(taskManager.get("freeSlots").asInt() <= NUM_SLOTS);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.fasterxml.jackson.databind.ObjectMapper in project camel by apache.
the class JacksonObjectMapperTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
ObjectMapper mapper = new ObjectMapper();
JacksonDataFormat format = new JacksonDataFormat();
format.setObjectMapper(mapper);
from("direct:in").marshal(format);
from("direct:back").unmarshal(format).to("mock:reverse");
JacksonDataFormat prettyPrintDataFormat = new JacksonDataFormat();
prettyPrintDataFormat.setPrettyPrint(true);
from("direct:inPretty").marshal(prettyPrintDataFormat);
from("direct:backPretty").unmarshal(prettyPrintDataFormat).to("mock:reverse");
JacksonDataFormat formatPojo = new JacksonDataFormat(TestPojo.class);
from("direct:inPojo").marshal(formatPojo);
from("direct:backPojo").unmarshal(formatPojo).to("mock:reversePojo");
}
};
}
use of com.fasterxml.jackson.databind.ObjectMapper in project camel by apache.
the class ElasticsearchActionRequestConverter method toSearchRequest.
@Converter
public static SearchRequest toSearchRequest(Object queryObject, Exchange exchange) {
SearchRequest searchRequest = new SearchRequest(exchange.getIn().getHeader(ElasticsearchConstants.PARAM_INDEX_NAME, String.class)).types(exchange.getIn().getHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, String.class));
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
String queryText = null;
if (queryObject instanceof Map<?, ?>) {
Map<String, Object> mapQuery = (Map<String, Object>) queryObject;
// Remove 'query' prefix from the query object for backward compatibility
if (mapQuery.containsKey(ElasticsearchConstants.ES_QUERY_DSL_PREFIX)) {
mapQuery = (Map<String, Object>) mapQuery.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
}
try {
XContentBuilder contentBuilder = XContentFactory.contentBuilder(XContentType.JSON);
queryText = contentBuilder.map(mapQuery).string();
} catch (IOException e) {
LOG.error(e.getMessage());
}
} else if (queryObject instanceof String) {
queryText = (String) queryObject;
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode jsonTextObject = mapper.readValue(queryText, JsonNode.class);
JsonNode parentJsonNode = jsonTextObject.get(ElasticsearchConstants.ES_QUERY_DSL_PREFIX);
if (parentJsonNode != null) {
queryText = parentJsonNode.toString();
}
} catch (IOException e) {
LOG.error(e.getMessage());
}
} else {
// Cannot convert the queryObject into SearchRequest
return null;
}
searchSourceBuilder.query(QueryBuilders.wrapperQuery(queryText));
searchRequest.source(searchSourceBuilder);
return searchRequest;
}
use of com.fasterxml.jackson.databind.ObjectMapper in project camel by apache.
the class EndpointCompletionTest method assertParameterJsonSchema.
private String assertParameterJsonSchema(MBeanServer mbeanServer, ObjectName on, String componentName) throws Exception {
Object[] params = { componentName };
String[] signature = { "java.lang.String" };
String answer = assertIsInstanceOf(String.class, mbeanServer.invoke(on, "componentParameterJsonSchema", params, signature));
LOG.info("Component " + componentName + " returned JSON: " + answer);
// now lets validate that the generated JSON parses correctly
ObjectMapper mapper = new ObjectMapper();
HashMap data = mapper.readValue(answer, HashMap.class);
LOG.info("Read JSON: " + data);
return answer;
}
use of com.fasterxml.jackson.databind.ObjectMapper in project redisson by redisson.
the class JsonJacksonMapValueCodecTest method shouldDeserializeTheMapCorrectly.
@Test
public void shouldDeserializeTheMapCorrectly() throws Exception {
ByteBuf buf = new PooledByteBufAllocator(true).buffer();
buf.writeBytes(new ObjectMapper().writeValueAsBytes(map));
assertThat(mapCodec.getMapValueDecoder().decode(buf, new State(false))).isInstanceOf(Map.class).isEqualTo(map);
}
Aggregations