json generation is incorrect using struts2 json plugin for camelCase fields

169 views Asked by At
private Integer iDisplayLength ;

public Integer getIDisplayLength() {
        return iDisplayLength;
    }

    public void setIDisplayLength(Integer iDisplayLength) {
        this.iDisplayLength = iDisplayLength;
    }

If the request contains iDisplayLength, it's set perfectly and I can see the value in action. But when the response returns (json-response) then it returns

IDisplayLength instead of iDisplayLength

Seems like a bug to me. Am I doing it wrong ? Are those getters & setters incorrect ?

My struts.xml looks like :

<action name="c/list" class="actions.MyAction" method="list">
            <result name="*" type="json"></result>
</action>

Update

I went through the plugin source code at : https://github.com/apache/struts2/blob/STRUTS_2_3_15_X/plugins/json/src/main/java/org/apache/struts2/json/JSONWriter.java

After replicating the method it uses to figure out a fields' name :

public static void main(String[] args) throws Exception {
        Class clazz = new IoAction().getClass();

        BeanInfo info = getBeanInfoIgnoreHierarchy(clazz);

        PropertyDescriptor[] props = info.getPropertyDescriptors();

        boolean hasData = false;
        for (PropertyDescriptor prop : props) {
            System.out.println("Field Name : "+prop.getName());
        }
    }

In IoAction there are getters/setters like :

public String getISortCol_0() {
        return iSortCol_0;
    }

    public void setISortCol_0(String iSortCol_0) {
        this.iSortCol_0 = iSortCol_0;
    }

And the above code prints Field Name as ISortCol_0 which is incorrect (IMHO), it should have returned iSortCol_0 Is it a bug in the java reflection API ?

0

There are 0 answers