Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mhabib23 opened this issue Jun 22, 2018 · 0 comments · May be fixed by #285
Open

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

mhabib23 opened this issue Jun 22, 2018 · 0 comments · May be fixed by #285

Comments

@mhabib23
Copy link

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?

@mhabib23 mhabib23 changed the title @Valid doesn't work with @javax.validation.Valid doesn't work Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant