Search in sources :

Example 86 with ObjectMapper

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());
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 87 with ObjectMapper

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");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 88 with ObjectMapper

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;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) Map(java.util.Map) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) Converter(org.apache.camel.Converter)

Example 89 with ObjectMapper

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;
}
Also used : HashMap(java.util.HashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 90 with ObjectMapper

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);
}
Also used : State(org.redisson.client.handler.State) ByteBuf(io.netty.buffer.ByteBuf) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1706 Test (org.junit.Test)641 JsonNode (com.fasterxml.jackson.databind.JsonNode)270 IOException (java.io.IOException)238 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)183 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)127 Map (java.util.Map)124 HashMap (java.util.HashMap)119 ArrayList (java.util.ArrayList)81 File (java.io.File)72 InputStream (java.io.InputStream)65 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)55 JCodeModel (com.sun.codemodel.JCodeModel)52 List (java.util.List)49 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)47 JPackage (com.sun.codemodel.JPackage)44 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)41 JsonException (jmri.server.json.JsonException)41 JType (com.sun.codemodel.JType)38 Test (org.testng.annotations.Test)37