简体   繁体   English

HashMap上的Jax-rs / Jersey Bean验证

[英]Jax-rs/Jersey Bean Validation on HashMap

I have a class that is already annotated with various constraints: 我有一个已经用各种约束注释的类:

public class SomeBean
{
   @NotNull
   public String name;

   public String description;
}

I have a resource that accepts a HashMap of SomeBean : 我有一个接受SomeBeanHashMapSomeBean

public class SomeBeans extends LinkedHashMap<String, SomeBean>
{
}

When I try to pass in @Valid final SomeBeans , it does not validate each individual SomeBean . 当我尝试传递@Valid final SomeBeans ,它不会验证每个单独的SomeBean For example, they can send in a SomeBean with a null name: 例如,他们可以发送名称为null的SomeBean

@POST
@Consumes( MeadiaType.APPLICATION_JSON )
public SomeBeans makeSomeBeans( @Valid final SomeBeans beans )
{
  // beans is not validated!
}

Do I need to write a custom validator for SomeBeans or is this supported already? 我需要为SomeBeans编写自定义验证器还是已经支持此验证器?

Thanks in advance! 提前致谢!

Unfortunately, there is no collection(or map in this case) validation support like that. 不幸的是,没有像这样的集合(或地图)验证支持。 Either you need to write custom validators or use this . 您需要编写自定义验证程序或使用this Not sure if it supports maps yet though. 虽然不确定它是否支持地图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM