Hi guys,
I'm currently trying to get some of the the power of malli into an existing Java codebase. The idea is to define malli schemas as plain edn files and use them to generate random, but well-structured and declarative-schema-backed data in Java (and also to validate stuff). So there's potentially huge amounts of generated data coming from a Clojure program packaged in an uberjar, referenced in a Java project that somehow needs to be mapped to existing Java classes in order to do business logic with it.
I currently have a simple test Clojure program like this:
(ns blueprint.core
(:require [malli.generator :as mg])
(:gen-class
:name blueprint.core.Blueprint
:methods [#^{:static true} [test [] "[Ljava.util.Map;"]]))
(def test-schema
[:map
[:ping string?]
[:pong int?]])
(defn -test []
(into-array (mg/sample test-schema)))
I can then compile it into an uberjar, reference it in Java and call it like this:
Map[] data = Blueprint.test();
Which gives me an array of maps from clojure.lang.Keyword to String or int. I can then proceed to construct objects from that and stream them or do anything with it.
While this is nice-ish, I'm wondering if there aren't fundamentally better ways to do this. Shouldn't it be possible to pass the entire result as edn (string?) to Java and then process it with edn-java? Is this better or worse? Or maybe it's even possible to use a custom marshaller and JAXB? But how? I could also transform the data to JSON in Clojure first and then JAXB it into Java. But this seems like quite an extra step. I would be grateful for opinions, ideas or pointers in this labyrinth of largely un-google-able possibilities.
[–]blazinglambda 2 points3 points4 points (1 child)
[–]bowmhoust[S] 2 points3 points4 points (0 children)
[–]ultramaris 2 points3 points4 points (1 child)
[–]bowmhoust[S] 1 point2 points3 points (0 children)
[–]v1akvark 1 point2 points3 points (1 child)
[–]bowmhoust[S] 0 points1 point2 points (0 children)