Example usage for com.fasterxml.jackson.databind.node ObjectNode put

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode put

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode put.

Prototype

public ObjectNode put(String paramString1, String paramString2) 

Source Link

Usage

From source file:com.github.fge.jsonschema.load.RefResolverTest.java

@Test
public void danglingRefsAreReported() {
    final ObjectNode node = JacksonUtils.nodeFactory().objectNode();
    node.put("$ref", "#/a");

    final SchemaTree tree = new CanonicalSchemaTree(node);
    final ValueHolder<SchemaTree> holder = ValueHolder.hold("schema", tree);

    try {/*from   w  ww  . j a v  a 2 s  . co  m*/
        processor.process(report, holder);
        fail("No exception thrown!");
    } catch (ProcessingException e) {
        assertMessage(e.getProcessingMessage()).hasMessage(BUNDLE.getString("danglingRef"));
    }
}

From source file:com.ibm.watson.catalyst.corpus.document.Document.java

public ObjectNode toJson() {
    ObjectNode result = MAPPER.createObjectNode();

    result.put("file", _file.toString());
    result.put("pauID", _pauID);
    result.put("pauTitle", _pauTitle);
    result.put("sourceDoc", _sourceDoc);
    result.set("paragraphs", JsonUtil.toArrayNodeString(_paragraphs));

    return result;
}

From source file:com.unboundid.scim2.extension.messages.consent.OAuth2ClientTest.java

/**
 * Tests serialization of Client objects.
 *
 * @throws Exception if an error occurs.
 *//*from   w  w  w .  jav a 2  s  .c om*/
@Test
public void testSerialization() throws Exception {
    String name = "testName";
    String description = "testDescription";
    String url = "https://localhost:12345/test/app/url";
    String iconUrl = "https://localhost:12345/test/icon/url";
    String emailAddress = "unit@test.com";

    ObjectNode objectNode = JsonUtils.getJsonNodeFactory().objectNode();
    objectNode.put("name", name);
    objectNode.put("description", description);
    objectNode.put("iconUrl", iconUrl);
    objectNode.put("url", url);
    objectNode.put("emailAddress", emailAddress);

    OAuth2Client app1 = JsonUtils.getObjectReader().forType(OAuth2Client.class)
            .readValue(objectNode.toString());
    Assert.assertEquals(app1.getName(), name);
    Assert.assertEquals(app1.getDescription(), description);
    Assert.assertEquals(app1.getIconUrl(), iconUrl);
    Assert.assertEquals(app1.getEmailAddress(), emailAddress);

    OAuth2Client app2 = JsonUtils.getObjectReader().forType(OAuth2Client.class)
            .readValue(JsonUtils.getObjectWriter().writeValueAsString(app1));
    Assert.assertEquals(app1, app2);
}

From source file:com.unboundid.scim2.extension.messages.externalidentity.ProviderTest.java

/**
 * Tests serialization of Provider objects.
 *
 * @throws Exception if an error occurs.
 *//*from  w w  w. java 2 s . c o  m*/
@Test
public void testSerialization() throws Exception {
    String name = "testName";
    String description = "testDescription";
    String iconUrl = "https://localhost:12345/test/url";
    String type = "testType";
    String samlResponseBinding = "artifact";

    ObjectNode objectNode = JsonUtils.getJsonNodeFactory().objectNode();
    objectNode.put("name", name);
    objectNode.put("description", description);
    objectNode.put("iconUrl", iconUrl);
    objectNode.put("type", type);
    objectNode.put("samlResponseBinding", samlResponseBinding);

    Provider provider1 = JsonUtils.getObjectReader().forType(Provider.class).readValue(objectNode.toString());
    Assert.assertEquals(provider1.getName(), name);
    Assert.assertEquals(provider1.getDescription(), description);
    Assert.assertEquals(provider1.getType(), type);
    Assert.assertEquals(provider1.getIconUrl(), iconUrl);
    Assert.assertEquals(provider1.getSamlResponseBinding(), samlResponseBinding);

    Provider provider2 = JsonUtils.getObjectReader().forType(Provider.class)
            .readValue(JsonUtils.getObjectWriter().writeValueAsString(provider1));
    Assert.assertEquals(provider1, provider2);
}

From source file:org.opendaylight.sfc.sbrest.json.SfstExporterFactory.java

@Override
public String exportJsonNameOnly(DataObject dataObject) {
    String ret = null;/* w ww .j av  a2s.  c om*/

    if (dataObject instanceof ServiceFunctionSchedulerType) {
        ServiceFunctionSchedulerType obj = (ServiceFunctionSchedulerType) dataObject;

        ObjectNode node = mapper.createObjectNode();
        node.put(_NAME, obj.getName());
        ArrayNode sfstArray = mapper.createArrayNode();
        sfstArray.add(node);
        ret = "{\"" + _SERVICE_FUNCTION_SCHEDULE_TYPE + "\":" + sfstArray.toString() + "}";
    } else {
        throw new IllegalArgumentException("Argument is not an instance of ServiceFunctionSchedulerType");
    }

    return ret;
}

From source file:com.redhat.lightblue.metadata.constraints.UIDFieldsTest.java

@Test
public void uidWithIdentity_initialized() throws Exception {
    // create basic metadata
    EntityMetadata entityMetadata = new EntityMetadata("test");

    // add uid field with identity constraint
    SimpleField f = new SimpleField("simpleUID", UIDType.TYPE);
    List<FieldConstraint> lfc = new ArrayList<>();
    lfc.add(new IdentityConstraint());
    f.setConstraints(lfc);/*from  w w w  .j  a v  a2s.  c  o m*/
    entityMetadata.getFields().addNew(f);

    // create document with uid value set
    ObjectNode node = nodeFactory.objectNode();
    node.put("simpleUID", 10);
    JsonDoc doc = new JsonDoc(node);

    // initialize uid fields
    UIDFields.initializeUIDFields(nodeFactory, entityMetadata, doc);

    // verify uid is not null
    Assert.assertNotNull(doc.get(new Path("simpleUID")));
}

From source file:org.activiti.rest.service.api.legacy.management.JobsExecuteResource.java

@Post
public ObjectNode startProcessInstance(Representation entity) {
    try {/*  ww  w  . j  a v  a2s  .  c o  m*/
        if (authenticate(SecuredResource.ADMIN) == false)
            return null;

        String startParams = entity.getText();
        JsonNode startJSON = new ObjectMapper().readTree(startParams);
        ArrayNode jobIdsJSON = (ArrayNode) startJSON.get("jobIds");
        for (JsonNode jobId : jobIdsJSON) {
            ActivitiUtil.getManagementService().executeJob(jobId.textValue());
        }

        ObjectNode successNode = new ObjectMapper().createObjectNode();
        successNode.put("success", true);
        return successNode;

    } catch (Exception e) {
        if (e instanceof ActivitiException) {
            throw (ActivitiException) e;
        } else {
            throw new ActivitiException("Failed to execute jobs", e);
        }
    }
}

From source file:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.DataflowActivityParser.java

@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean,
        ParserState parserState) throws ReaderException {
    DataflowConfig dataflowConfig = unmarshallConfig(t2FlowParser, configBean, "dataflow",
            DataflowConfig.class);
    Configuration configuration = new Configuration();
    configuration.setType(nestedUri.resolve("#Config"));

    String wfId = dataflowConfig.getRef();
    URI wfUri = WORKFLOW_ROOT.resolve(wfId + "/");
    Workflow wf = (Workflow) getUriTools().resolveUri(wfUri, parserState.getCurrentWorkflowBundle());
    if (wf == null)
        throw new ReaderException("Can't find nested workflow with id " + wfId);
    ObjectNode json = configuration.getJsonAsObjectNode();
    json.put("nestedWorkflow", wf.getName());
    return configuration;
}

From source file:mobile.service.RNSService.java

private static ServiceResult createOrUpdateService(ObjectNode data, ObjectNodeResult returnRawResult) {
    if (data.hasNonNull("id")) {
        Long id = data.get("id").asLong();
        Service service = Service.queryServiceById(id);
        if (null == service) {
            return ServiceResult.error("1008", "??");
        }//www. j a va  2  s.c o  m
    }

    if ("-1".equals(data.path("price").asText())) {
        data.put("price", "");
    }

    ObjectNodeResult objectNodeResult = ServicesService.createOrUpdateService(MobileUtil.getCurrentUser(),
            data);
    if (null != returnRawResult) {
        returnRawResult.setAll(objectNodeResult.getObjectNode());
    }

    // ?
    if (!objectNodeResult.isSuccess()) {
        if ("800002".equals(objectNodeResult.getErrorCode())) {
            return ServiceResult.error("1001", objectNodeResult.getError());
        } else if ("-301".equals(objectNodeResult.getErrorCode())) {
            return ServiceResult.error("1004", "???");
        }
        Logger.error(objectNodeResult.getObjectNode().toString());
        return ServiceResult.error("100001", "");
    }

    return ServiceResult.success();
}

From source file:mobile.service.RNSService.java

private static ServiceResult createOrUpdateRequire(ObjectNode data, ObjectNodeResult returnRawResult) {
    if (data.hasNonNull("id")) {
        Long id = data.get("id").asLong();
        Require require = Require.queryRequireById(id);
        if (null == require) {
            return ServiceResult.error("1007", "?");
        }/*from   www  .ja  va2s.  c  o  m*/
    }

    if ("-1".equals(data.path("budget").asText())) {
        data.put("budget", "");
    }

    ObjectNodeResult objectNodeResult = RequireService.createOrUpdateService(MobileUtil.getCurrentUser(), data);
    if (null != returnRawResult) {
        returnRawResult.setAll(objectNodeResult.getObjectNode());
    }

    // ?
    if (!objectNodeResult.isSuccess()) {
        if ("700002".equals(objectNodeResult.getErrorCode())) {
            return ServiceResult.error("1001", objectNodeResult.getError());
        } else if ("-301".equals(objectNodeResult.getErrorCode())) {
            return ServiceResult.error("1003", "??");
        }
        Logger.error(objectNodeResult.getObjectNode().toString());
        return ServiceResult.error("100001", "");
    }

    return ServiceResult.success();
}