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");
}
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);
}
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);
}
}
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;
}
}
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;
}
}
Aggregations