Skip to content
This repository was archived by the owner on Dec 18, 2020. It is now read-only.

Java Annotations Research

William Gardiner edited this page Mar 21, 2019 · 9 revisions

Resources

Creating an annotation: Creating Custom Annotations in Java

Useful JavaDocs:

General Solution

Annotation Interface

This interface contains a method for each of the fields. Non-required fields have default specified. They must return a primitive type or a 1-dimensional array there of. Here is a sample of what the @SwaggerGeneratorEndpoint annotation make look like:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface SwaggerGeneratorEndpoint {

	String url();
	String method();
	String description();
	String[] headers() default {};
	Class<?> body() default BlankClass.class;
	String[] responses();
	String[] parameters() default {};
	String scheme() default "HTTP";

}

class BlankClass {
}

Annotation Implementation

Finally, we have the method that will implement the functionality of the annotation. This method is implemented as any other method would be, however will likely make heavy use of Java's reflections library. This method will access the information provided in an instance of an annotation via the interface defined earlier. This method must be called explicitly.

Other Links

SwaggerGen Annotation Usage

Clone this wiki locally