Menu

#3 Option to strictly adhere to Javabean conventions

open
nobody
None
5
2007-04-25
2007-04-25
No

If you have a simple class like so...

class ViewState {
private String xLoc = "10px";
public void setXLoc(String val) {
xLoc = val;
}
public String getXLoc() {
return xLoc;
}
}

...when Flexjson serializes it, the result is:

{"XLoc": "10px"}

Note the case of the field returned: XLoc, vs. xLoc as it appears in the class definition. The class follows Javabean conventions correctly, but the returned JSON doesn't strictly honor these conventions.

It would therefore be nice to have an option that allows you to get this behavior. As Charlie described to me privately, Flexjson is using the BeanIntrospector classes to do its work, and apparently it looks at the methods rather than the fields the class contains. Therefore, I would imagine the option would reverse that: get a list of the fields in the class and then call the appropriate Javabean-spec-compliant getter for it (i.e., capitalize the first letter of the field name and prepend get, so getXLoc() in this case for the xLoc field).

Discussion


Log in to post a comment.