Search in sources :

Example 6 with JSONObject

use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.

the class PlaceableTest method getResourceTags.

private static Set<String> getResourceTags(BOperator bop) {
    JSONObject placement = JOperatorConfig.getJSONItem(bop.json(), PLACEMENT);
    if (placement == null)
        return null;
    JSONArray jat = (JSONArray) placement.get(com.ibm.streamsx.topology.generator.operator.OpProperties.PLACEMENT_RESOURCE_TAGS);
    if (jat == null)
        return null;
    Set<String> tags = new HashSet<>();
    for (Object rt : jat) tags.add(rt.toString());
    return tags;
}
Also used : JSONObject(com.ibm.json.java.JSONObject) JSONArray(com.ibm.json.java.JSONArray) JSONObject(com.ibm.json.java.JSONObject) HashSet(java.util.HashSet)

Example 7 with JSONObject

use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.

the class JSONStreamsTest method testJSONAble.

@Test
public void testJSONAble() throws IOException, Exception {
    Topology topology = new Topology();
    final TestJSONAble value = new TestJSONAble(42, QUESTION);
    TStream<TestJSONAble> s = topology.constants(Collections.singletonList(value)).asType(TestJSONAble.class);
    TStream<JSONObject> js = JSONStreams.toJSON(s);
    JSONObject ev = new JSONObject();
    ev.put("b", QUESTION);
    ev.put("a", 42l);
    checkJsonOutput(ev, JSONStreams.serialize(js));
}
Also used : JSONObject(com.ibm.json.java.JSONObject) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 8 with JSONObject

use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.

the class JSONStreamsTest method testFlattenNoObjects.

@Test
public void testFlattenNoObjects() throws Exception {
    final Topology t = new Topology();
    final JSONObject value = new JSONObject();
    final JSONArray array = new JSONArray();
    array.add("hello");
    value.put("greetings", array);
    TStream<JSONObject> s = t.constants(Collections.singletonList(value));
    TStream<JSONObject> jsonm = JSONStreams.flattenArray(s, "greetings");
    TStream<String> output = JSONStreams.serialize(jsonm);
    JSONObject payload = new JSONObject();
    payload.put("payload", "hello");
    completeAndValidate(output, 10, payload.toString());
}
Also used : JSONObject(com.ibm.json.java.JSONObject) JSONArray(com.ibm.json.java.JSONArray) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Example 9 with JSONObject

use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.

the class KafkaStreamsTest method toJson.

private static String toJson(Message m) {
    JSONObject jo = new JSONObject();
    jo.put("key", m.getKey());
    jo.put("message", m.getMessage());
    jo.put("topic", m.getTopic());
    return jo.toString();
}
Also used : JSONObject(com.ibm.json.java.JSONObject)

Example 10 with JSONObject

use of com.ibm.json.java.JSONObject in project streamsx.topology by IBMStreams.

the class JSONStreamsTest method testModifyingJson.

@Test
public void testModifyingJson() throws Exception {
    final Topology t = new Topology("SimpleJson");
    final JSONObject value = new JSONObject();
    value.put("question", QUESTION);
    TStream<JSONObject> s = t.constants(Collections.singletonList(value));
    TStream<String> jsonString = JSONStreams.serialize(s);
    TStream<JSONObject> json = JSONStreams.deserialize(jsonString);
    TStream<JSONObject> jsonm = modifyJSON(json);
    assertFalse(value.containsKey("answer"));
    JSONObject ev = new JSONObject();
    ev.put("question", QUESTION);
    ev.put("answer", 42l);
    checkJsonOutput(ev, JSONStreams.serialize(jsonm));
}
Also used : JSONObject(com.ibm.json.java.JSONObject) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Aggregations

JSONObject (com.ibm.json.java.JSONObject)56 JSONArray (com.ibm.json.java.JSONArray)19 Topology (com.ibm.streamsx.topology.Topology)18 Test (org.junit.Test)18 TestTopology (com.ibm.streamsx.topology.test.TestTopology)14 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)6 Tester (com.ibm.streamsx.topology.tester.Tester)5 JsonObject (com.google.gson.JsonObject)4 HashMap (java.util.HashMap)4 Random (java.util.Random)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 OrderedJSONObject (com.ibm.json.java.OrderedJSONObject)2 StreamConnection (com.ibm.streams.flow.declare.StreamConnection)2 StreamSchema (com.ibm.streams.operator.StreamSchema)2 BOperatorInvocation (com.ibm.streamsx.topology.builder.BOperatorInvocation)2 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 Attribute (com.ibm.streams.operator.Attribute)1