Enforce not-null field in JSON object

后端 未结 4 805
余生分开走
余生分开走 2020-12-10 00:43

Our REST API receives some JSON objects input where some fields are required to be not null. Those can be either String/Integer or even might be some other class instance as

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-10 01:20

    @Required is a Spring framework annotation for injected beans, so I'd say don't use it for this purpose.

    You can use this one instead:

    http://robaustin.wikidot.com/annotations-and-notnull

    @NotNull String myString;

    For runtime checks, try http://code.google.com/p/notnullcheckweaver/

提交回复
热议问题