IBMStreams / streamsx.topology

Develop streaming applications for IBM Streams in Python, Java & Scala.
http://ibmstreams.github.io/streamsx.topology
Apache License 2.0
29 stars 43 forks source link

[Java Topology] Proposal: Add support for publish/subscribe using Gson #839

Closed cancilla closed 4 years ago

cancilla commented 7 years ago

I would like to propose that the Java Topology API be enhanced to support publish and subscribe using Gson. Having integrated Gson support would be beneficial as it allows for finer grained control over the serialization and deserialization processes. It also allows for going directly from a JSON string to a Java object.

The following are an initial set of APIs that I believe would be beneficial. I am proposing that we pass an instance of Gson directly to the publish() and subscribe() method as it gives the user full control over how the Gson instance is constructed.

/*
 * Uses the specified Gson instance to serialize the object of type T into a JSON string. The SPL schema is JSONSchemas.JSON. 
 */
TStream<T>.publish(String topic, Gson gson)

/*
 * Uses the specifies Gson instance to deserialize the incoming JSON string into an object of the specified type.
 */
Topology.subscribe(String topic, Gson gson, Class<T> classOfT)

I look forward to discussing this point further.

ddebrunner commented 7 years ago

+1 to the concept, we need to decide if we "pollute" the high level interfaces with Gson or instead have utilities in a com.ibm.streamsx.topology.gson package.

We also need to easily have streams of JsonObject (Gson) as well as the existingJSONObject (JSON4J).