Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added @IgnoreParameter meta annotation #3577

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions retrofit/src/main/java/retrofit2/IgnoreParameter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package retrofit2;


import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Use this meta-annotation on an annotation you want to use on a service method parameter to cause
* retrofit to ignore the parameter when processing a request.
*/
@Documented
@Target(TYPE)
@Retention(RUNTIME)
public @interface IgnoreParameter {
}
9 changes: 9 additions & 0 deletions retrofit/src/main/java/retrofit2/ParameterHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,13 @@ void apply(RequestBuilder builder, @Nullable T value) {
builder.addTag(cls, value);
}
}

static final class NoOp<T> extends ParameterHandler<T> {

@Override
void apply(RequestBuilder builder, @org.jetbrains.annotations.Nullable T value) throws IOException {
// do nothing
}
}

}
8 changes: 7 additions & 1 deletion retrofit/src/main/java/retrofit2/RequestFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -803,9 +803,15 @@ private ParameterHandler<?> parseParameterAnnotation(
}

return new ParameterHandler.Tag<>(tagType);
} else if (shouldIgnoreParameter(annotation)) {
return new ParameterHandler.NoOp<>();
}

return null; // Not a Retrofit annotation.
return null; // No ParameterHandler for annotation.
}

private boolean shouldIgnoreParameter(Annotation annotation){
return annotation.getClass().isAnnotationPresent(IgnoreParameter.class);
}

private void validateResolvableType(int p, Type type) {
Expand Down