There is this really nice maven plugin that takes JSON schema and generates Java POJOs
annotated with GSON annotations. I took this stuff and created a sample module in the bus
repo and see how it works. It works very nicely and I think we can use this very easily in
our stuff.
First, here is a site that discusses JSON schema if you aren't familiar (its
essentially like XML Schema only for JSON):
http://json-schema.org/documentation.html
We can use this maven plugin to generate an API that our Java components can use to talk
to each other. To see what the generated code looks like with any JSON schema, here's
a play area where you can see it in realtime:
http://www.jsonschema2pojo.org/
Here's what my sample JSON schema looks like (you'll see it uses primitives as
well as sets/lists and embedded types (see address type) and a set of embedded types (see
phoneNumbers):
https://github.com/hawkular/hawkular-bus/blob/master/hawkular-bus-samples...
Here is where my test code creates the message via the POJO API that was generated by the
maven plugin:
https://github.com/hawkular/hawkular-bus/blob/master/hawkular-bus-samples...
If we use this stuff, we write the JSON schema which automatically provides documentation
that non-Java clients can use to know what the clients need to send/consume, or they can
use the schema themselves to generate their own client code. We use the schema internally
to generate Java POJOs that we then use in our Java components (like what my sample code
demonstrates).
Here is what the maven plugin usage looks like - its pretty simple:
https://github.com/hawkular/hawkular-bus/blob/master/hawkular-bus-samples...