@Test public void supportedParameters() throws Exception { assertTrue(this.processor.supportsParameter(this.paramNamedValidModelAttr)); assertTrue(this.processor.supportsParameter(this.paramModelAttr)); assertFalse(this.processor.supportsParameter(this.paramErrors)); assertFalse(this.processor.supportsParameter(this.paramInt)); assertFalse(this.processor.supportsParameter(this.paramNonSimpleType)); }
@Test public void supportedParametersInDefaultResolutionMode() throws Exception { processor = new ModelAttributeMethodProcessor(true); // Only non-simple types, even if not annotated assertTrue(this.processor.supportsParameter(this.paramNamedValidModelAttr)); assertTrue(this.processor.supportsParameter(this.paramErrors)); assertTrue(this.processor.supportsParameter(this.paramModelAttr)); assertTrue(this.processor.supportsParameter(this.paramNonSimpleType)); assertFalse(this.processor.supportsParameter(this.paramInt)); }
@Override public boolean supportsParameter(MethodParameter parameter) { if (!super.supportsParameter(parameter)) { return false; } Class<?> type = parameter.getParameterType(); if (!type.isInterface()) { return false; } // Annotated parameter if (parameter.getParameterAnnotation(ProjectedPayload.class) != null) { return true; } // Annotated type if (AnnotatedElementUtils.findMergedAnnotation(type, ProjectedPayload.class) != null) { return true; } // Fallback for only user defined interfaces String packageName = ClassUtils.getPackageName(type); return !IGNORED_PACKAGES.stream().anyMatch(it -> packageName.startsWith(it)); }