Skip to content

Latest commit

 

History

History
60 lines (51 loc) · 2.77 KB

README.md

File metadata and controls

60 lines (51 loc) · 2.77 KB

Build Status Maven Central Javadocs

jaxrs-client-gen

Generate JAX-RS resource client source files.

Handles both classes and interfaces with JAX-RS resource annotations. Class derived resources can generate both synchronous and asynchronous clients.

<dependency>
  <groupId>io.github.yeagy</groupId>
  <artifactId>jaxrs-client-gen</artifactId>
  <version>0.2.2</version>
</dependency>

#####Usage To use from the command line, use the *-capsule.jar, which is executable:

java -jar <capsule jar> [options] [<dir>|<filename>]+

The --async (-a) flag will generate asynchronous clients from resources.
The --parent-classpath (-pcp) option takes a semicolon separated list of dependencies your clients require
A directory will be created named 'jaxrs-client-gen' which will contain all the generated sources.

Here is an example that will generate sources from the test classes of this project:

java -jar build/libs/jaxrs-client-gen-0.2.2-capsule.jar build/classes/test

On UNIX like systems the jar is self-executing:

build/libs/jaxrs-client-gen-0.2.2-capsule.jar build/classes/test

Afterwards you can copy the generated sources into your source tree:

cp -r jaxrs-client-gen/* src/main/java/.

Known limitations

  • Sub-resources not supported.
  • Targets Java6, so parameter names cannot be known via reflection. This library will use the JAX-RS annotation values as parameter names instead. 95% of the time, it works every time.
  • This library is forgiving with a mismatch of the parameter name and the corresponding annotation value (which typically match). One notable exception: any field setters or constructor parameters annotated with @*Param types, the annotation value should match the name of the backing field or getter used to call the method. This is a Java6 limitation. Note: annotating the backing field directly allows label mismatch.
class MyBeanParam{
    private String example;
    
    @QueryParam("anything")
    private String something;
    
    //any annotation value other than "example" would fail in this case.
    public MyBeanParam(@QueryParam("example") String foo, String bar) {
        this.example = foo;
        this.something = bar;
    }
    
    public String getExample() { return example; }
    public String getSomething() { return something; }
}