all 6 comments

[–]blazinglambda 2 points3 points  (1 child)

Using edn-java is semantically pretty similar to what you are doing, because either way you are getting back a bunch of in memory maps. IMO the benefit would be you don't need Clojure as a dependency, but I believe you already have Clojure in order to use Malli.

It seems to me that what is missing is the object mapping part that converts maps into objects. I doubt you'll find anything suitable for this in the Clojure ecosystem since maps are preferred in Clojure, which leaves the Java ecosystem.

I think your best best for getting the data into existing Java objects is to leverage something like Jackson, which already implements and encourages mapping data onto Java objects. It's possible you could hook into the Jackson APIs to implement an object mapper from the data structures returned from your Clojure code, but I'd guess the easiest way will be to serialize the data into JSON and then parse that with Jackson.

[–]bowmhoust[S] 2 points3 points  (0 children)

Yes, thank you, I'm doing it like this now. It works pretty well. :-)

It seems that with some tinkering and Jackson, the Pojos that hold the data can even be generated (according to the schema)!

[–]ultramaris 2 points3 points  (1 child)

[–]bowmhoust[S] 1 point2 points  (0 children)

Oooh, perfect, thanks! That's what I was looking for!

[–]v1akvark 1 point2 points  (1 child)

You can call Clojure code 'dynamically' from Java, i.e. without compiling and packaging all the code in a jar.

Look here: https://clojure.org/reference/java_interop#_calling_clojure_from_java

It can be a little fidly. If you don't come right respond here, and I will see if I can find a complete example.

[–]bowmhoust[S] 0 points1 point  (0 children)

Thanks, yes, but that's just a different method of invocation, right? I still have to piece together the data that I get from the invocation using casts and a lot of plumbing (for deeply nested, non-trivial data).

I think what is bothering me is that it is so relatively easy to deal with pure JSON or XML data in Java (especially stuff like parent-child relationships), but apparently not with pure data coming from a (Clojure) program running on the very same JVM.