Open jypma opened 7 years ago
I recently created akka/akka#21826, sort of related to this
Oh yes, don't mind if I plug the lib there as well :)
Looks interesting. I will probably take a look.
@ktoso mentioned that it may be a better fit to have ts-reaktive-marshal
augment/replace the JSON framing support in akka-http
, rather than have it in alpakka
.
@jypma we finally looked at ts-reaktive again during last week's team meeting. Sorry for delaying this for so long.
We think it is indeed a good fit for alpakka. We looked at the code a bit which looks well-structured so it shouldn't be too hard to extract.
The scope would be the ts-reaktive-marshal and ts-reaktive-marshal-http modules. I'll try to summarize the functionality (please correct if I'm wrong):
Here are a few remarks:
WDYT?
Adding context from gitter chat on last Friday which Johannes missed:
Jan Ypma @jypma Mar 23 11:30 I was a bit worried "requiring" a certain version... but actually, now I think of it, the bindings for their collections possibly need to change together with the version anyways. OK, let's go for implementation depends on Javaslang plain Java collection bindings separate from javaslang bindings (can be in the same JAR though, javaslang is already on board) scala bindings in a separate JAR ? however, the internal API would then still hava Javaslang signatures. In other words, if one would want to add support for e.g. YAML or sth, you'd be coding against Javaslang classes.
Patrik Nordwall @patriknw Mar 23 11:34 sounds good, but why scala bindings in separate jar (scala is also already a dependency)?
Jan Ypma @jypma Mar 23 11:40 it isn't. It only is for the layer that binds the marshalling to akka streams. The basic marshalling doesn't depend on scala (or akka). The thing can conceivably be used with e.g. RxJava
@ktoso is this acceptable as far as scala marshalling DSL? https://github.com/Tradeshift/ts-reaktive/pull/56/files#diff-87884016caa105133b216b64cd5088faR17 If so, I'll park that PR and start working on a first PR onto alpakka, as tentatively talked about with Patrik.
And just as a sanity check: I think Johannes's summary contains everything we discussed. So the parsing is one thing, and the nice glue code for HTTP is another :)
The marshalling part of ts-reaktive (small presentation and demos here) provides a DSL to describe bi-directional marshalling of custom data types to and from XML or JSON. A short example:
The above
XMLProtocol
can then be used to create an akkaFlow
that (with proper back-pressure) takesXMLEvent
in andPerson
out, or,Person
in andXMLEvent
out.The result would read and write something like this:
An equivalent DSL exists for JSON, but using actual JSON primitives instead.
Combinators like
arrayList
,option
, etc. are shared between the two DSL.I think it's a nice fit for alpakka, since it allows us to describe higher-level XML API's in a streaming fashion. For example, we could streamingly list an S3 bucket. Note that akka-http's current streaming marshalling capabilities depend on specific "framing" use cases. This proposed library can split stream elements at (almost) arbitrary locations.
It'd need a Scala API in addition to the Java one of course, but that's small potatoes.
What do you think?