55 */
66package io .jooby .internal .apt ;
77
8- import static io .jooby .internal .apt .AnnotationSupport .findAnnotationValue ;
9- import static io .jooby .internal .apt .Types .BUILT_IN ;
10- import static java .util .stream .Collectors .joining ;
11-
8+ import javax .lang .model .element .*;
129import java .util .*;
1310import java .util .function .Predicate ;
1411import java .util .stream .Stream ;
1512
16- import javax .lang .model .element .*;
13+ import static io .jooby .internal .apt .AnnotationSupport .findAnnotationValue ;
14+ import static io .jooby .internal .apt .Types .BUILT_IN ;
15+ import static java .util .stream .Collectors .joining ;
1716
1817public enum ParameterGenerator {
1918 ContextParam ("getAttribute" , "io.jooby.annotation.ContextParam" , "jakarta.ws.rs.core.Context" ) {
@@ -23,6 +22,7 @@ public String toSourceCode(
2322 MvcRoute route ,
2423 AnnotationMirror annotation ,
2524 TypeDefinition type ,
25+ VariableElement parameter ,
2626 String name ,
2727 boolean nullable ) {
2828 if (type .is (Map .class )) {
@@ -70,6 +70,7 @@ public String toSourceCode(
7070 MvcRoute route ,
7171 AnnotationMirror annotation ,
7272 TypeDefinition type ,
73+ VariableElement parameter ,
7374 String name ,
7475 boolean nullable ) {
7576 var rawType = type .getRawType ().toString ();
@@ -107,6 +108,7 @@ public String toSourceCode(
107108 MvcRoute route ,
108109 AnnotationMirror annotation ,
109110 TypeDefinition type ,
111+ VariableElement parameter ,
110112 String name ,
111113 boolean nullable ) {
112114 List <Element > converters = new ArrayList <>();
@@ -200,10 +202,11 @@ public String toSourceCode(
200202 MvcRoute route ,
201203 AnnotationMirror annotation ,
202204 TypeDefinition type ,
205+ VariableElement parameter ,
203206 String name ,
204207 boolean nullable ) {
205208 var paramSource = source (annotation );
206- var builtin = builtinType (kt , annotation , type , name , nullable );
209+ var builtin = builtinType (kt , annotation , type , parameter , name , nullable );
207210 if (builtin == null ) {
208211 // List, Set,
209212 var toValue =
@@ -323,10 +326,15 @@ public String toSourceCode(
323326 }
324327
325328 protected String builtinType (
326- boolean kt , AnnotationMirror annotation , TypeDefinition type , String name , boolean nullable ) {
329+ boolean kt ,
330+ AnnotationMirror annotation ,
331+ TypeDefinition type ,
332+ VariableElement parameter ,
333+ String name ,
334+ boolean nullable ) {
327335 if (BUILT_IN .stream ().anyMatch (type ::is )) {
328336 var paramSource = source (annotation );
329- var defaultValue = defaultValue (annotation );
337+ var defaultValue = defaultValue (parameter , annotation );
330338 // look at named parameter
331339 if (type .isPrimitive ()) {
332340 // like: .intValue
@@ -425,10 +433,19 @@ protected String source(AnnotationMirror annotation) {
425433 return "" ;
426434 }
427435
428- protected String defaultValue (AnnotationMirror annotation ) {
429- if (annotation .getAnnotationType ().toString ().startsWith ("io.jooby.annotation" )) {
436+ protected String defaultValue (VariableElement parameter , AnnotationMirror annotation ) {
437+ var annotationType = annotation .getAnnotationType ().toString ();
438+
439+ if (annotationType .startsWith ("io.jooby.annotation" )) {
430440 var sources = findAnnotationValue (annotation , AnnotationSupport .VALUE );
431441 return sources .isEmpty () ? "" : CodeBlock .of (", " , CodeBlock .string (sources .getFirst ()));
442+ } else if (annotationType .startsWith ("jakarta.ws.rs" )) {
443+ var defaultValueAnnotation = AnnotationSupport .findAnnotationByName (
444+ parameter , "jakarta.ws.rs.DefaultValue" );
445+ if (defaultValueAnnotation != null ) {
446+ var defaultValue = findAnnotationValue (defaultValueAnnotation , AnnotationSupport .VALUE );
447+ return defaultValue .isEmpty () ? "" : CodeBlock .of (", " , CodeBlock .string (defaultValue .getFirst ()));
448+ }
432449 }
433450 return "" ;
434451 }
0 commit comments