Search in sources :

Example 61 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project pulsar by yahoo.

the class LookupDataTest method serializeToJsonTest.

@SuppressWarnings("unchecked")
@Test
void serializeToJsonTest() throws Exception {
    LookupData data = new LookupData("pulsar://localhost:8888", "pulsar://localhost:8884", "http://localhost:8080", "http://localhost:8081");
    ObjectMapper mapper = ObjectMapperFactory.getThreadLocal();
    String json = mapper.writeValueAsString(data);
    Map<String, String> jsonMap = mapper.readValue(json, Map.class);
    assertEquals(jsonMap.get("brokerUrl"), "pulsar://localhost:8888");
    assertEquals(jsonMap.get("brokerUrlTls"), "pulsar://localhost:8884");
    assertEquals(jsonMap.get("brokerUrlSsl"), "");
    assertEquals(jsonMap.get("nativeUrl"), "pulsar://localhost:8888");
    assertEquals(jsonMap.get("httpUrl"), "http://localhost:8080");
    assertEquals(jsonMap.get("httpUrlTls"), "http://localhost:8081");
}
Also used : LookupData(com.yahoo.pulsar.common.lookup.data.LookupData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 62 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project pulsar by yahoo.

the class NamespaceOwnershipStatusTest method testSerialization.

@Test
void testSerialization() throws Exception {
    String jsonStr = "{\"ns-1\":{\"broker_assignment\":\"shared\",\"is_controlled\":false,\"is_active\":true}," + "\"ns-2\":{\"broker_assignment\":\"primary\",\"is_controlled\":true,\"is_active\":false}," + "\"ns-3\":{\"broker_assignment\":\"secondary\",\"is_controlled\":true,\"is_active\":true}}";
    ObjectMapper jsonMapper = ObjectMapperFactory.create();
    Map<String, NamespaceOwnershipStatus> nsMap = jsonMapper.readValue(jsonStr.getBytes(), new TypeReference<Map<String, NamespaceOwnershipStatus>>() {
    });
    assertEquals(nsMap.size(), 3);
    for (String ns : nsMap.keySet()) {
        NamespaceOwnershipStatus nsStatus = nsMap.get(ns);
        if (ns.equals("ns-1")) {
            assertEquals(nsStatus.broker_assignment, BrokerAssignment.shared);
            assertFalse(nsStatus.is_controlled);
            assertTrue(nsStatus.is_active);
        } else if (ns.equals("ns-2")) {
            assertEquals(nsStatus.broker_assignment, BrokerAssignment.primary);
            assertTrue(nsStatus.is_controlled);
            assertFalse(nsStatus.is_active);
        } else if (ns.equals("ns-3")) {
            assertEquals(nsStatus.broker_assignment, BrokerAssignment.secondary);
            assertTrue(nsStatus.is_controlled);
            assertTrue(nsStatus.is_active);
        }
    }
    assertEquals(jsonMapper.writeValueAsString(nsMap), jsonStr);
}
Also used : NamespaceOwnershipStatus(com.yahoo.pulsar.common.policies.data.NamespaceOwnershipStatus) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 63 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project camel by apache.

the class ConnectorCatalogNexusRepository method addCustomCamelConnectorFromArtifact.

/**
     * Adds any discovered third party Camel connectors from the artifact.
     */
private void addCustomCamelConnectorFromArtifact(NexusArtifactDto dto, URL jarUrl) {
    try (URLClassLoader classLoader = new URLClassLoader(new URL[] { jarUrl })) {
        String[] json = loadConnectorJSonSchema(classLoader);
        if (json != null) {
            ObjectMapper mapper = new ObjectMapper();
            JsonNode tree = mapper.readTree(json[0]);
            String name = tree.get("name").textValue();
            String scheme = tree.get("scheme").textValue();
            String javaType = tree.get("javaType").textValue();
            String description = tree.get("description").textValue();
            Iterator<JsonNode> it = tree.withArray("labels").iterator();
            CollectionStringBuffer csb = new CollectionStringBuffer(",");
            while (it.hasNext()) {
                String text = it.next().textValue();
                csb.append(text);
            }
            addConnector(dto, name, scheme, javaType, description, csb.toString(), json[0], json[1], json[2]);
        }
    } catch (IOException e) {
        log.warn("Error scanning JAR for custom Camel components", e);
    }
}
Also used : CollectionStringBuffer(org.apache.camel.catalog.CollectionStringBuffer) URLClassLoader(java.net.URLClassLoader) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 64 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project camel by apache.

the class CamelCatalogRest method asEndpointUriXml.

@POST
@Path("/asEndpointUriXml/{scheme}")
@Consumes("application/json")
@Produces("text/plain")
@ApiOperation(value = "Creates an endpoint uri in XML style configured using the provided options in the JSon body")
public String asEndpointUriXml(@ApiParam(value = "The component scheme", readOnly = true) @PathParam("scheme") String scheme, @ApiParam(value = "The options as a JSon map with key/value pairs", required = true) String json) {
    try {
        ObjectMapper mapper = new ObjectMapper();
        Map map = mapper.readValue(json, Map.class);
        return catalog.asEndpointUriXml(scheme, map, true);
    } catch (Exception e) {
        return null;
    }
}
Also used : Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Example 65 with ObjectMapper

use of com.fasterxml.jackson.databind.ObjectMapper in project camel by apache.

the class CamelConnectorCatalogRest method asEndpointUriXml.

@POST
@Path("/asEndpointUriXml/{scheme}")
@Consumes("application/json")
@Produces("text/plain")
@ApiOperation(value = "Creates an endpoint uri in XML style configured using the provided options in the JSon body")
public String asEndpointUriXml(@ApiParam(value = "The component scheme", readOnly = true) @PathParam("scheme") String scheme, @ApiParam(value = "The options as a JSon map with key/value pairs", required = true) String json) {
    try {
        ObjectMapper mapper = new ObjectMapper();
        Map map = mapper.readValue(json, Map.class);
        return catalog.asEndpointUriXml(scheme, map, true);
    } catch (Exception e) {
        return null;
    }
}
Also used : Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

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