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:de.cubeisland.engine.core.webapi.TextWebSocketFrameEncoder.java

@Override
protected void encode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception {
    if (msg instanceof String) {
        ObjectNode node = objectMapper.createObjectNode();
        node.put("desc", (String) msg);
        out.add(new TextWebSocketFrame(node.toString()));
    } else if (msg instanceof JsonNode) {
        out.add(new TextWebSocketFrame(msg.toString()));
    } else {/*from   www.  ja v  a2  s  .  com*/
        out.add(msg);
    }
}

From source file:com.collective.celos.servlet.JSONWorkflowServletTest.java

@Test
public void jsonCorrectlyProduced() throws Exception {
    ScheduledTime t1 = new ScheduledTime("2013-12-20T20:00:00.000Z");
    ScheduledTime t2 = new ScheduledTime("2013-12-20T21:00:00.000Z");
    WorkflowID wfID = new WorkflowID("foobar");
    SlotState s1 = new SlotState(new SlotID(wfID, t1), SlotState.Status.READY);
    SlotState s2 = new SlotState(new SlotID(wfID, t2), SlotState.Status.RUNNING, "external-ID", 4);
    List<SlotState> states = new LinkedList<SlotState>();
    states.add(s1);//from   w ww . j  av a  2  s  .  c  o m
    states.add(s2);

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode node = mapper.createObjectNode();
    node.put(t1.toString(), s1.toJSONNode());
    node.put(t2.toString(), s2.toJSONNode());

    Assert.assertEquals(node, new JSONWorkflowServlet().createJSONObject(states));
}

From source file:com.ibm.watson.catalyst.corpus.tfidf.sentences.Bigram.java

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

    result.put("word1", _word1);
    result.put("word2", _word2);

    return result;
}

From source file:com.ikanow.aleph2.graph.titan.utils.TitanGraphBuildingUtils.java

/** Inserts a single-valued vertex property into a JSON object
 * @param f/*from w w  w . jav  a 2  s .  c om*/
 * @param vp
 * @param o
 * @return
 */
protected static ObjectNode insertIntoObjectNode(final String f, final Property<Object> vp,
        final ObjectNode o) {
    return Patterns.match(vp.value()).<ObjectNode>andReturn().when(String.class, s -> o.put(f, s))
            .when(Double.class, d -> o.put(f, d)).when(Integer.class, i -> o.put(f, i))
            .when(Long.class, i -> o.put(f, i)).when(Boolean.class, b -> o.put(f, b)).otherwise(__ -> o);
}

From source file:yadarts.server.json.ScoreEncoder.java

@Override
public ObjectNode encode(Score t, MediaType mt) {
    ObjectNode node = new ObjectNode(createJSONNodeFactory());

    node.put("darts", t.getThrownDarts());
    node.put("points", t.getTotalScore());
    node.put("totalTime", t.getTotalTime());

    return node;/*  w ww .j  ava 2s  .c om*/
}

From source file:yadarts.server.json.GameStateEncoder.java

@Override
public ObjectNode encode(GameScoreSummary t, MediaType mt) {
    ObjectNode node = createNewEmptyObject();
    node.put("name", t.getName());
    ObjectNode scores = createNewEmptyObject();

    if (t.getPlayers() != null) {
        for (Player p : t.getPlayers()) {
            Score s = t.getScores().get(p);
            scores.put(p.getName(), (s == null ? createNewEmptyObject() : scoreEncoder.encode(s, mt)));
        }//w w w.j  av  a 2  s . co  m
        node.put("scores", scores);
    }

    return node;
}

From source file:com.github.fge.jsonschema.core.tree.JsonTreeTest.java

@BeforeClass
public void init() {
    childObject = factory.objectNode();//from   w  w  w. j a v  a  2 s  .  c om
    childObject.put("a", "b");

    final ObjectNode rootNode = factory.objectNode();
    rootNode.put("object", childObject);
    testNode = rootNode;
}

From source file:azkaban.crypto.CryptoV1.java

@Override
public String encrypt(String plaintext, String passphrase, Version cryptoVersion) {
    Preconditions.checkArgument(Version.V1_0.equals(cryptoVersion));

    String cipheredText = newEncryptor(passphrase).encrypt(plaintext);
    ObjectNode node = MAPPER.createObjectNode();
    node.put(CIPHERED_TEXT_KEY, cipheredText);
    node.put(ICrypto.VERSION_IDENTIFIER, Version.V1_0.versionStr());

    return Crypto.encode(node.toString());
}

From source file:com.dhenton9000.json.processing.FasterXMLJSONTests.java

@Test
public void testModifiedTreeToString() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode sampleTree = mapper.readTree(TEST_STRING);
    ObjectNode sampleObj = (ObjectNode) sampleTree;
    sampleObj.put("alpha", 99);
    assertEquals(sampleTree.toString(), "{\"alpha\":99,\"beta\":\"get a job\"}");

}

From source file:org.eclipse.winery.repository.Utils.java

public static String getAllXSDefinitionsForTypeAheadSelection(short type) {
    SortedSet<XSDImportId> allImports = Repository.INSTANCE.getAllTOSCAComponentIds(XSDImportId.class);

    Map<Namespace, Collection<String>> data = new HashMap<>();

    for (XSDImportId id : allImports) {
        XSDImportResource resource = new XSDImportResource(id);
        Collection<String> allLocalNames = resource.getAllDefinedLocalNames(type);

        Collection<String> list;
        if ((list = data.get(id.getNamespace())) == null) {
            // list does not yet exist
            list = new ArrayList<>();
            data.put(id.getNamespace(), list);
        }//from   w w  w.jav a  2 s  .  c o m
        list.addAll(allLocalNames);
    }

    ArrayNode rootNode = Utils.mapper.createArrayNode();

    // ensure ordering in JSON object
    Collection<Namespace> allns = new TreeSet<>();
    allns.addAll(data.keySet());

    for (Namespace ns : allns) {
        Collection<String> localNames = data.get(ns);
        if (!localNames.isEmpty()) {
            ObjectNode groupEntry = Utils.mapper.createObjectNode();
            rootNode.add(groupEntry);
            groupEntry.put("text", ns.getDecoded());
            ArrayNode children = Utils.mapper.createArrayNode();
            groupEntry.put("children", children);
            Collection<String> sortedLocalNames = new TreeSet<>();
            sortedLocalNames.addAll(localNames);
            for (String localName : sortedLocalNames) {
                String value = "{" + ns.getDecoded() + "}" + localName;
                //noinspection UnnecessaryLocalVariable
                String text = localName;
                ObjectNode o = Utils.mapper.createObjectNode();
                o.put("text", text);
                o.put("value", value);
                children.add(o);
            }
        }
    }

    try {
        return Utils.mapper.writeValueAsString(rootNode);
    } catch (JsonProcessingException e) {
        throw new IllegalStateException("Could not create JSON", e);
    }
}