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;
}
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));
}
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());
}
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();
}
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));
}
Aggregations