Get the fields name that contain @Size annotation along with their max length

I have this entity -

public class Employee{
private Integer employeeId;

private String employeeName;

private Long employeeSalary;

I want to get the name of the fields along with their maximum length allowed. That is, for above case the output should be like

employeeId - 5
employeeName - 40

I have created this following which returns the name of the fields that contain @Size

public boolean hasSize() {
                .anyMatch(field -> field.isAnnotationPresent(Size.class));
public List<String> getSizeFields(){
        if(hasSize()) {
            Stream<Field> filter =
                    .filter(field -> field.isAnnotationPresent(Size.class));
            return -> obj.getName()).collect(Collectors.toList());
            return null;

Suggest me how can I get the max length of the fields as well.

Read more here:

Content Attribution

This content was originally published by Bhumika at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: