support for fluent setters

21 views
Skip to first unread message

Ryan Schneider

unread,
Mar 28, 2014, 11:12:23 PM3/28/14
to po...@googlegroups.com
It appears that PODAM only discovers setters if they return void. However all of my objects in my projects are written with fluency for the extreme convenience it gets to chain sets together and avoid numerous constructors.

public class MyClass {
    private String myVariable;
    public String getMyVariable() { return myVariable; }
    public MyClass setMyVariable( String myVariable ) { this.myVariable = myVariable; return this; }
}

However in the PODAM code, it explicitly short circuits this:

    public static Set<Method> getPojoSetters(Class<?> clazz, Set<String> classFields) {

        Set<Method> classSetters = new HashSet<Method>();

        while (clazz != null) {

            Method[] declaredMethods = clazz.getDeclaredMethods();
            String candidateField = null;
            for (Method method : declaredMethods) {
                if (!method.getName().startsWith("set")) {
                    continue;
                }
                if (!method.getReturnType().equals(void.class)) {
                    continue;
                }
                candidateField = extractFieldNameFromSetterMethod(method);
                if (!classFields.contains(candidateField)) {
                    continue;
                }
                classSetters.add(method);

            }
            clazz = clazz.getSuperclass();
        }

        return classSetters;
    }


I understand it goes against bean convention, and the default behavior should not be changed. However would folks be open to making this and optional setting when calling manufacturePojo or when creating a factory? I can contribute the changes pretty easily.

Thanks,
Ryan

Marco Tedone

unread,
Jul 8, 2015, 6:40:36 PM7/8/15
to po...@googlegroups.com, ryan.sc...@gmail.com
Podam allows users to specify additional methods to invoke during bean instantiation. Look at AbstractClassInfoStrategy addExtraMethod
Reply all
Reply to author
Forward
0 new messages