Example usage for com.fasterxml.jackson.databind.node JsonNodeFactory instance

List of usage examples for com.fasterxml.jackson.databind.node JsonNodeFactory instance

Introduction

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

Prototype

JsonNodeFactory instance

To view the source code for com.fasterxml.jackson.databind.node JsonNodeFactory instance.

Click Source Link

Usage

From source file:net.hamnaberg.json.Property.java

private static ObjectNode makeObject(String name, Optional<String> prompt) {
    ObjectNode node = JsonNodeFactory.instance.objectNode();
    node.put("name", name);
    prompt.ifPresent(value -> node.put("prompt", value));
    return node;/*w w w  .  ja  v  a2s. com*/
}

From source file:io.gs2.identifier.Gs2IdentifierClient.java

/**
 * ??????<br>/* www .j  ava 2 s . co  m*/
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public CreateSecurityPolicyResult createSecurityPolicy(CreateSecurityPolicyRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("name", request.getName()).put("policy",
            request.getPolicy());

    HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/securityPolicy", credential, ENDPOINT,
            CreateSecurityPolicyRequest.Constant.MODULE, CreateSecurityPolicyRequest.Constant.FUNCTION,
            body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(post, CreateSecurityPolicyResult.class);

}

From source file:com.redhat.lightblue.util.JsonUtils.java

/**
 * Converts a Java object tree containing maps and collections to json
 *///from   w ww.  java 2  s . c o m
public static JsonNode toJson(Object obj) {
    if (obj == null) {
        return JsonNodeFactory.instance.nullNode();
    } else if (obj instanceof Map) {
        return toJson((Map) obj);
    } else if (obj instanceof Collection) {
        return toJson((Collection) obj);
    } else {
        return valueToJson(obj);
    }
}

From source file:org.apache.streams.rss.serializer.SyndEntryActivitySerializer.java

/**
 * Given an RSS object and an existing activity,
 * add the Rome extension to that activity and return it
 *
 * @param activity/*from  ww  w .ja v  a2 s  .  c om*/
 * @param entry
 * @return
 */
private Activity addRomeExtension(Activity activity, ObjectNode entry) {
    ObjectMapper mapper = StreamsJacksonMapper.getInstance();
    ObjectNode activityRoot = mapper.convertValue(activity, ObjectNode.class);
    ObjectNode extensions = JsonNodeFactory.instance.objectNode();

    extensions.put("rome", entry);
    activityRoot.put("extensions", extensions);

    activity = mapper.convertValue(activityRoot, Activity.class);

    return activity;
}

From source file:io.fabric8.collector.elasticsearch.ElasticsearchClient.java

public ObjectNode createIndexMappingIfMissing(final String index, final String type,
        Function<ObjectNode, Boolean> updater) {
    ObjectNode metadata = WebClients.handle404ByReturningNull(new Callable<ObjectNode>() {
        @Override/* ww  w .j  a  v  a2  s  .  c  o m*/
        public ObjectNode call() throws Exception {
            return getIndexMapping(index, type);
        }
    });
    boolean create = false;
    JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
    if (metadata == null) {
        create = true;
        metadata = nodeFactory.objectNode();
    }
    ObjectNode properties = null;
    JsonNode propertiesNode = metadata.path(index).path("mappings").path(type).path("properties");
    if (propertiesNode.isObject()) {
        properties = (ObjectNode) propertiesNode;
    } else {
        create = true;
        properties = JsonNodes.setObjects(metadata, index, "mappings", type, "properties");
    }
    if (properties == null) {
        LOG.warn("Failed to create object path!");
    }
    if (!updater.apply(properties)) {
        return null;
    }
    if (create) {
        ObjectNode typeNode = (ObjectNode) metadata.path(index).path("mappings").path(type);
        return getElasticsearchAPI().updateIndexMapping(index, type, typeNode);
    } else {
        return null;
    }
}

From source file:org.apache.taverna.scufl2.api.ExampleWorkflow.java

public Profile makeSecondaryProfile() {
    Profile profile = makeMainProfile();
    profile.setName("tavernaServer");
    Configuration config = profile.getConfigurations().getByName("Hello");
    ObjectNode json = JsonNodeFactory.instance.objectNode();
    json.put("script",
            "hello = \"Hello, \" + personName;\n" + "System.out.println(\"Server says: \" + hello);");
    config.setJson(json);/*from   www.j a va 2 s .  c o  m*/
    return profile;
}

From source file:io.gs2.notification.Gs2NotificationClient.java

/**
 * ????<br>//from w  w w.j a  v  a 2  s. com
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public CreateSubscribeResult createSubscribe(CreateSubscribeRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("type", request.getType()).put("endpoint",
            request.getEndpoint());

    HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/notification/"
            + (request.getNotificationName() == null || request.getNotificationName().equals("") ? "null"
                    : request.getNotificationName())
            + "/subscribe", credential, ENDPOINT, CreateSubscribeRequest.Constant.MODULE,
            CreateSubscribeRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(post, CreateSubscribeResult.class);

}

From source file:com.arpnetworking.metrics.proxy.models.protocol.v2.MetricMessagesProcessor.java

private void processMetricsList(final MetricsList metricsList) {
    //TODO(barp): Map with a POJO mapper [MAI-184]
    final ObjectNode dataNode = JsonNodeFactory.instance.objectNode();
    final ArrayNode services = JsonNodeFactory.instance.arrayNode();
    for (final Map.Entry<String, Map<String, Set<String>>> service : metricsList.getMetrics().entrySet()) {
        final ObjectNode serviceObject = JsonNodeFactory.instance.objectNode();
        serviceObject.put("name", service.getKey());
        final ArrayNode metrics = JsonNodeFactory.instance.arrayNode();
        for (final Map.Entry<String, Set<String>> metric : service.getValue().entrySet()) {
            final ObjectNode metricObject = JsonNodeFactory.instance.objectNode();
            metricObject.put("name", metric.getKey());
            final ArrayNode stats = JsonNodeFactory.instance.arrayNode();
            for (final String statistic : metric.getValue()) {
                final ObjectNode statsObject = JsonNodeFactory.instance.objectNode();
                statsObject.put("name", statistic);
                statsObject.set("children", JsonNodeFactory.instance.arrayNode());
                stats.add(statsObject);/*from   w w w.  jav  a 2 s. com*/
            }
            metricObject.set("children", stats);
            metrics.add(metricObject);
        }
        serviceObject.set("children", metrics);
        services.add(serviceObject);
    }
    dataNode.set("metrics", services);
    _connection.sendCommand(COMMAND_METRICS_LIST, dataNode);
}

From source file:com.redhat.lightblue.util.JsonUtils.java

private static JsonNode toJson(Map obj) {
    ObjectNode node = JsonNodeFactory.instance.objectNode();
    for (Iterator<Map.Entry> itr = obj.entrySet().iterator(); itr.hasNext();) {
        Map.Entry entry = itr.next();
        node.set((String) entry.getKey(), toJson(entry.getValue()));
    }//  www  . ja  va  2s .  c  o m
    return node;
}

From source file:io.gs2.realtime.Gs2RealtimeClient.java

/**
 * ????<br>/*from   ww  w.  j  av  a 2s .c om*/
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public CreateGatheringResult createGathering(CreateGatheringRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode();
    if (request.getName() != null)
        body.put("name", request.getName());
    if (request.getUserIds() != null)
        body.put("userIds", request.getUserIds());

    HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/gatheringPool/"
            + (request.getGatheringPoolName() == null || request.getGatheringPoolName().equals("") ? "null"
                    : request.getGatheringPoolName())
            + "/gathering", credential, ENDPOINT, CreateGatheringRequest.Constant.MODULE,
            CreateGatheringRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(post, CreateGatheringResult.class);

}