Search in sources :

Example 81 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project exhibitor by soabase.

the class ExplorerResource method getNode.

@GET
@Path("node")
@Produces("application/json")
public String getNode(@QueryParam("key") String key) throws Exception {
    ArrayNode children = JsonNodeFactory.instance.arrayNode();
    try {
        List<String> childrenNames = context.getExhibitor().getLocalConnection().getChildren().forPath(key);
        SmartSort.sortChildren(childrenNames);
        for (String name : childrenNames) {
            ObjectNode node = children.addObject();
            node.put("title", name);
            node.put("key", ZKPaths.makePath(key, name));
            node.put("isLazy", true);
            node.put("expand", false);
        }
    } catch (Throwable e) {
        context.getExhibitor().resetLocalConnection();
        context.getExhibitor().getLog().add(ActivityLog.Type.ERROR, "getNode: " + key, e);
        ObjectNode node = children.addObject();
        node.put("title", "* Exception *");
        node.put("key", ERROR_KEY);
        node.put("isLazy", false);
        node.put("expand", false);
    }
    return children.toString();
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayNode(org.codehaus.jackson.node.ArrayNode)

Example 82 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project modules.playframework.org by playframework.

the class FeaturedModules method update.

public static Result update() {
    Result result;
    Form<FeaturedModule> form = form(FeaturedModule.class).bindFromRequest();
    if (form.hasErrors()) {
        result = badRequest(form.errorsAsJson());
    } else {
        FeaturedModule incoming = form.get();
        FeaturedModule storedVersion = FeaturedModule.FIND.byId(incoming.id);
        storedVersion.description = StringUtils.isEmpty(incoming.description) ? storedVersion.playModule.description : incoming.description;
        storedVersion.sticky = incoming.sticky;
        storedVersion.save();
        // Annoying - converting storedVersion directly to JSON results in a cycle according to Jackson
        // Buggered if I can see why though
        ObjectNode node = Json.newObject();
        node.put("id", storedVersion.id);
        node.put("description", storedVersion.description);
        node.put("sticky", storedVersion.sticky);
        result = ok(node);
    }
    return result;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) FeaturedModule(models.FeaturedModule) Result(play.mvc.Result)

Example 83 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project stanbol by apache.

the class AnalyzedTextParser method parseAnalyzedTextSpan.

private void parseAnalyzedTextSpan(JsonNode node, AnalysedText at) throws IOException {
    if (node.isObject()) {
        ObjectNode jSpan = (ObjectNode) node;
        int[] spanPos = new int[] { -1, -1 };
        Collection<Entry<String, JsonNode>> jAnnotations = new ArrayList<Entry<String, JsonNode>>(4);
        SpanTypeEnum spanType = parseSpanData(jSpan, spanPos, jAnnotations);
        if (spanType != SpanTypeEnum.Text || spanPos[0] != 0 || spanPos[1] < 0) {
            throw new IOException("The AnalyzedText span MUST have the SpanType 'text', a " + "start position of '0' and an end position (ignored, json: " + jSpan);
        }
        if (at.getEnd() != spanPos[1]) {
            throw new IOException("The size of the local text '" + at.getEnd() + "' does not " + "match the span of the parsed AnalyzedText [" + spanPos[0] + "," + spanPos[1] + "]!");
        }
        parseAnnotations(at, jAnnotations);
    } else {
        throw new IOException("Unable to parse AnalyzedText span form JsonNode " + node + " (expected JSON object)!");
    }
}
Also used : Entry(java.util.Map.Entry) SpanTypeEnum(org.apache.stanbol.enhancer.nlp.model.SpanTypeEnum) ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(org.codehaus.jackson.JsonNode) SerializedString(org.codehaus.jackson.io.SerializedString) IOException(java.io.IOException)

Example 84 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project stanbol by apache.

the class NerTagSupport method serialize.

@Override
public ObjectNode serialize(ObjectMapper mapper, NerTag nerTag) {
    ObjectNode jNerTag = mapper.createObjectNode();
    jNerTag.put("tag", nerTag.getTag());
    if (nerTag.getType() != null) {
        jNerTag.put("uri", nerTag.getType().getUnicodeString());
    }
    return jNerTag;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode)

Example 85 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project stanbol by apache.

the class PhraseTagSupport method serialize.

@Override
public ObjectNode serialize(ObjectMapper mapper, PhraseTag value) {
    ObjectNode jTag = mapper.createObjectNode();
    jTag.put("tag", value.getTag());
    if (value.getCategory() != null) {
        jTag.put("lc", value.getCategory().ordinal());
    }
    return jTag;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode)

Aggregations

ObjectNode (org.codehaus.jackson.node.ObjectNode)97 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)29 ArrayNode (org.codehaus.jackson.node.ArrayNode)29 JsonNode (org.codehaus.jackson.JsonNode)22 GET (javax.ws.rs.GET)21 Path (javax.ws.rs.Path)18 Test (org.junit.Test)16 Produces (javax.ws.rs.Produces)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 IOException (java.io.IOException)8 StringWriter (java.io.StringWriter)5 JsonFactory (org.codehaus.jackson.JsonFactory)5 HelixDataAccessor (org.apache.helix.HelixDataAccessor)4 Span (org.apache.stanbol.enhancer.nlp.model.Span)4 DatasetImpl (org.eol.globi.service.DatasetImpl)4 Date (java.util.Date)3 TaskDriver (org.apache.helix.task.TaskDriver)3 WorkflowConfig (org.apache.helix.task.WorkflowConfig)3