Game form validation

I am creating a Play application with Play 2.3 in Java.

I am trying to use a form to process a POST request with a JSON body.

My problem is that if my JSON is a simple object with only String or Floats attribute, it works well. But if I placed the Object imbrication part, it continues to bind the request in different ways, but does not perform constraint checking on nested objects.

Here is an example of what I'm trying to do:

public class PairRequest { @Required public String epc; @Required public RequestProduct product; } public class RequestProduct { //Product data @Constraints.Required private String productCode; @Constraints.Required public Brand brand; @Constraints.Required private String furniture; } @Entity public class Brand extends Model { @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long id; @Column(length = 250) @Constraints.Required public String name; @Column(nullable = true, length = 512) public String regex; } 

Did I miss something? This is strange because I think it worked for the first time ... But I cannot be sure.

0
source share
1 answer

Not only @Required annotation is @Required , but also @Valid for complex objects, as indicated here: Automatically generate form data (JSON)

+1
source

Source: https://habr.com/ru/post/944602/


All Articles