soabase / soabase-halva

Idiomatic Scala ... in Java
https://github.com/soabase/soabase-halva/blob/master/README.md
Apache License 2.0
81 stars 5 forks source link

Think about supporting Bean Validation 1.1 annotations on fields #37

Closed azell closed 8 years ago

azell commented 8 years ago

https://docs.jboss.org/hibernate/stable/beanvalidation/api/ http://beanvalidation.org/

It would be useful to support JSR-349 annotations on case classes. Unfortunately, the spec only supports property annotations on JavaBean getter methods. Halva could apply any supplied annotations on the field.

Ex:

@CaseClass
class Foo {
  @NotNull
  @Size(min = 8, max = 12)
  String type();
}

could generate:

class FooCase {
  @NotNull
  @Size(min = 8, max = 12)
  private final String type;
...

One implementation is to take the property annotations, filter out Jackson annotations and copy the remaining onto the field definition. See http://fasterxml.github.io/jackson-annotations/javadoc/2.7/com/fasterxml/jackson/annotation/JacksonAnnotation.html:

Meta-annotation (annotations used on other annotations) used for marking all annotations that are part of Jackson package. Can be used for recognizing all Jackson annotations generically, and in future also for passing other generic annotation configuration.
Randgalt commented 8 years ago

If you annotate the interface template it should work right? I don't think Halva needs to do anything additional.

azell commented 8 years ago

From what I remember from the JSR, annotations must be on the field or a getter method. A case class would need to look like:

@CaseClass
public interface Foo {
  @NotNull
  String getValue();
}

I am not sure if Halva supports the getXXX notation or wants to.

Randgalt commented 8 years ago

Fixed by #40