增强HttpUserType的类型校验

This commit is contained in:
Redkale
2018-08-28 10:18:27 +08:00
parent ac50312f0b
commit 750da161eb
2 changed files with 4 additions and 1 deletions

View File

@@ -12,7 +12,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* 配合 HttpServlet 使用。
* 用于指定HttpRequest.currentUser的数据类型。<br>
* 注意: 数据类型是JavaBean则必须要用javax.persistence.Id标记主键字段用于确定用户ID
* 注意: 数据类型是JavaBean
*
* <p>
* 详情见: https://redkale.org

View File

@@ -705,6 +705,9 @@ public final class Rest {
HttpUserType hut = baseServletType.getAnnotation(HttpUserType.class);
final Class userType = (userType0 == null || userType0 == Object.class) ? (hut == null ? null : hut.value()) : userType0;
if (userType != null && (userType.isPrimitive() || userType.getName().startsWith("java.") || userType.getName().startsWith("javax."))) {
throw new RuntimeException(HttpUserType.class.getSimpleName() + " must be a JavaBean but found " + userType);
}
final String supDynName = baseServletType.getName().replace('.', '/');
final RestService controller = serviceType.getAnnotation(RestService.class);