0

I have an JavaDTO like:

public class myDTO {
    private String name;
    private Integer age;
}

I want to do different validation in Micronaut by an CREATE operation and by an UPDATE operation. In Spring you can define different 'groups' therefore. See here stackoverflow link or here external link. So this looks like:

public class myDTO {
    @Null(groups = OnCreate.class)
    @NotNull(groups = OnUpdate.class)
    private String name;

    @Null(groups = OnCreate.class)
    @NotNull(groups = OnUpdate.class)
    private Integer age;
}

Is there something similiar for micronaut there?

Mafick
  • 1,128
  • 1
  • 12
  • 27
  • Is your question specific to Micronaut Data? – James Kleeh May 05 '20 at 18:29
  • I don't really understand what you mean. Yes, I am using Micronaut. As you can see in the links, Spring provides therefore a functionality. For Micronaut i didn't find anything for this. Also, I think it is more a 'core' functionality instead of 'data'. – Mafick May 06 '20 at 07:10

1 Answers1

1

I believe this is not Spring functionality but more how beans are validated from the javax bean validator.

You need to use Hibernate Validator where javax.persistence.validation.group.pre-update are applicable.

Default Micronaut bean validation is not using Hibernate Validator. Try to add hibernate validator as dependency.

https://micronaut-projects.github.io/micronaut-hibernate-validator/latest/guide/index.html

Traycho Ivanov
  • 2,887
  • 14
  • 24