Avoid using primitives when generating with RAML to JAX-RS


#1

Hello,

Is there any option or way of avoiding the usage of Java primitives when generating with RAML to JAX-RS? Specifically I’m using the RAML-to-JAX-RS CLI jar, v.3.0.2.

I would like to use Integer instead of int, Boolean instead of boolean, etc.

Is there a flag/option for the jar/generator?

Or should I “shadow” the types in the RAML file to Integer, Boolean, and other Java object names (and create dummy objects named like those)?

If so, how can I make the generated code reference the Java types and not the “dummy” generated ones? I would like a solution that doesn’t involve manually re-setting all references, since this would be needed every time code is generated.


#2

There is a raml2jaxrs plugin that you can use…

First here is the raml… you will actually have to create the file (name it whatever) and paste the contents found at this link into that file for your use:

Here is a short example of using that .raml file:

See this maven example of including it… you have to add a dependency in your maven configuration for using the raml2jaxrs maven plugin plugin:

Once you have that set up, you can now use the raml2jaxrs features plugin in your raml with annotations. I had a need to a UUID type to be generated (matching the json schema format: “uuid”). I did this in a common raml file I include/use in other raml types…

Uuid:
description: A version 4 UUID
(raml2pojo.types):
plugins:
- name: core.changeType
arguments: [ java.util.UUID ]
type: string

In my example I use raml2pojo as the name to the raml2jaxrs.raml file in the first link. You can name it whatever you want in your uses: section to reference it in your raml.

I dont know the exact syntax for using objects instead of primitives… but I believe there is a plugin option in there to do that. I saw something in the source but cant remember where so you may have to navigate the raml2jaxrs source (perhaps from within the links i pasted above) to find the primitive option.

I hope this helps. If I dig up any more info Ill be sure to share it.