Skip to content

@javax.validation.Valid doesn't work #222

Closed as not planned
Closed as not planned
@mhabib23

Description

@mhabib23

I'm trying to use json-rpc with spring boot and I'm not able to validate model fields.

public class Payload {
    @NotNull(message = "amount is mandatory")
    private BigDecimal amount;

    @NotNull(message = "currency is mandatory")
    private String currency;
    
    // setter & getter & constructors ...

}

@JsonRpcService("/generate")
public interface IGenerator {
    String generate(@Valid @JsonRpcParam(value = "payload") Payload payload);
}

@AutoJsonRpcServiceImpl
@Component
public class GeneratorImpl implements IGenerator {
    @Override
    public String generate(@Valid @JsonRpcParam(value = "payload") Payload payload) {
         return payload.getAmount() +" "+ payload.getCurrency();
    }
}

For that code I would expect if I didn't send amount or currency or both I would get ConstraintViolationException.

Is there any way to add validations on the model fields?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions