Example usage for com.fasterxml.jackson.databind ObjectMapper createObjectNode

List of usage examples for com.fasterxml.jackson.databind ObjectMapper createObjectNode

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper createObjectNode.

Prototype

@Override
public ObjectNode createObjectNode() 

Source Link

Document

Note: return type is co-variant, as basic ObjectCodec abstraction can not refer to concrete node types (as it's part of core package, whereas impls are part of mapper package)

Usage

From source file:org.openlmis.fulfillment.util.CustomSortDeserializerTest.java

@Test
public void shouldDeserializeArraySort() throws IOException {
    ObjectMapper mapper = new ObjectMapper();

    ObjectNode order = mapper.createObjectNode();
    order.put("direction", "DESC");
    order.put("property", "startDate");
    order.put("ignoreCase", false);
    order.put("nullHandling", "NATIVE");
    order.put("ascending", false);
    order.put("descending", true);

    ArrayNode arrayNode = mapper.createArrayNode();
    arrayNode.add(order);//from  w w  w  .j a va  2 s .c o  m

    ObjectNode testObject = mapper.createObjectNode();
    testObject.set("sort", arrayNode);

    Sort sort = deserialize(testObject.toString());

    assertEquals(Sort.Direction.DESC, sort.getOrderFor("startDate").getDirection());
}

From source file:com.appranix.adapter.service.AdapterServiceImpl.java

@Override
public int adapterCreate() throws Exception {
    try {/*from   www . ja va 2  s  .c  o m*/
        ObjectMapper mapper = new ObjectMapper();
        ObjectNode node = mapper.createObjectNode();
        node.put("nsPath", "/");
        node.put("ciClassName", "Component");
        node.put("ciName", "test");

        final String uri = "http://localhost:9090/adapter/rest/cm/simple/cis";

        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> result = restTemplate.postForEntity(uri, node, String.class);

        Map<String, Integer> map = mapper.readValue(result.getBody(), Map.class);

        Integer id = map.get("ciId");

        return id;
    } catch (Exception e) {
        throw new Exception("Error in Write Operation");
    }
}

From source file:com.github.lynxdb.server.api.http.handlers.EpError.java

@RequestMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity error(HttpServletRequest request, HttpServletResponse response) {

    HttpStatus status = HttpStatus.valueOf((int) request.getAttribute("javax.servlet.error.status_code"));

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode error = mapper.createObjectNode();
    error.put("code", status.value());
    error.put("message", status.getReasonPhrase());
    error.put("details", getErrorAttributes(request, true).get("message").toString());
    if (getErrorAttributes(request, true).get("exception") != null) {
        error.put("trace", getErrorAttributes(request, true).get("exception").toString() + "\n"
                + getErrorAttributes(request, true).get("trace").toString());
    }//from w w  w . ja  va  2 s  .  co  m

    return ResponseEntity.status(status).body(error.toString());
}

From source file:org.jboss.aerogear.sync.client.netty.JsonPatchClientIntegrationTest.java

@Test
public void connect() throws InterruptedException {
    final ObjectMapper objectMapper = new ObjectMapper();
    final ObjectNode originalVersion = objectMapper.createObjectNode().put("name", "fletch");
    final String documentId = "1234";
    final String clientId = "client2";
    final JsonPatchClientSynchronizer synchronizer = new JsonPatchClientSynchronizer();
    final ClientInMemoryDataStore<JsonNode, JsonPatchEdit> dataStore = new ClientInMemoryDataStore<JsonNode, JsonPatchEdit>();
    final ClientSyncEngine<JsonNode, JsonPatchEdit> clientSyncEngine = new ClientSyncEngine<JsonNode, JsonPatchEdit>(
            synchronizer, dataStore, new DefaultPatchObservable<JsonNode>());
    final NettySyncClient<JsonNode, JsonPatchEdit> client = NettySyncClient
            .<JsonNode, JsonPatchEdit>forHost("localhost").syncEngine(clientSyncEngine).port(7777).path("/sync")
            .build();//from w ww .ja va2 s  .c  o m
    client.connect();
    client.addDocument(clientDoc(documentId, clientId, originalVersion));
    Thread.sleep(1000);
    client.disconnect();
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.CreatingPlanVisibilityStep.java

private String prepareServiceVisibilityJsonRequest(String servicePlanGuid, String orgGuid) {

    ObjectMapper mapper = new ObjectMapper();

    ObjectNode json = mapper.createObjectNode();
    json.put("service_plan_guid", servicePlanGuid);
    json.put("organization_guid", orgGuid);

    return json.toString();
}

From source file:gist.ac.netcs.fwdtraffic.rest.FwdTrafficRestComponent.java

@GET
@Produces(MediaType.APPLICATION_JSON)//ww  w  .j  ava 2  s. co m
public Response getAll() {
    service = get(FwdTrafficService.class);
    map = service.getMap();
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode root = mapper.createObjectNode();
    ArrayNode dev = mapper.createArrayNode();
    ObjectNode element = mapper().createObjectNode();

    for (DeviceId devId : map.keySet()) {
        ArrayNode flow = mapper().createArrayNode();
        map.get(devId).forEach((k, v) -> flow.add(convert(k, v)));
        element.set(devId.toString(), flow);
    }

    // iterate the map, extract the element and fill up element JSON obj
    // hint: need to generate flow ArrayNode first, add converted
    // JSON object of host pair and counter into the flow
    // Add flow into element by specifying switch id

    dev.add(element);
    root.set("data", dev);
    return ok(root).build();
}

From source file:com.spotify.docker.client.messages.ProgressMessageTest.java

private ProgressMessage readMessage(final String status) throws IOException {
    final ObjectMapper objectMapper = new ObjectMapperProvider().getContext(ProgressMessage.class);
    final String line = objectMapper.createObjectNode().put("status", status).toString();
    return objectMapper.readValue(line, ProgressMessage.class);
}

From source file:org.wrml.runtime.format.application.vnd.wrml.design.schema.SchemaDesignFormatter.java

private static ObjectNode buildSyntaxNode(final ObjectMapper objectMapper, final Type heapValueType,
        final SyntaxLoader syntaxLoader) {

    if (!String.class.equals(heapValueType) && heapValueType instanceof Class<?>) {

        // TODO: Make it easy/possible to get the Syntax Document's title and uri

        final Class<?> heapValueClass = (Class<?>) heapValueType;
        final URI syntaxUri = syntaxLoader.getSyntaxUri(heapValueClass);
        final String syntaxName = heapValueClass.getSimpleName();
        final ObjectNode syntaxNode = objectMapper.createObjectNode();

        syntaxNode.put(PropertyName.title.name(), syntaxName);
        syntaxNode.put(PropertyName.uri.name(), syntaxUri.toString());
        return syntaxNode;
    }/* www  . j a  va  2  s .c o  m*/
    return null;
}

From source file:org.mascherl.session.MascherlSession.java

public MascherlSession(ObjectMapper objectMapper) {
    this(objectMapper, objectMapper.createObjectNode());
}

From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppRouteCreatingStep.java

private String createRouteBody(String subdomain, String domainGuid, String spaceGuid) {
    ObjectMapper mapper = new ObjectMapper();

    ObjectNode requestBody = mapper.createObjectNode();
    requestBody.put("host", subdomain);
    requestBody.put("domain_guid", domainGuid);
    requestBody.put("space_guid", spaceGuid);

    return requestBody.toString();
}