I use FlexJson for serialization, the only problem is that it generates the field names lower case while I need them to start with upper case:
class Person
{
String name;
public String getName() { return name;}
}
When serialized the field is serialized as name, while I need it to be Name.
How can I specify the output field name? Is there some attribute I can put to specify the required serialization name?
You can achieve this by using a Custom Transformer. As per Flexjson page transformer is:
Flexjson has provided an abstract class AbstractTransformer for this purpose; Extend and override
transform(Object object)to handle the transformation by yourself.Pasted below is the code of
FieldNameTransformerwhich I wrote for specifying the field name s manually:Following is how to use this custom transformer:
where original field’s name is ‘name’ but in json ouput it will be replaced with Name.
Sample out: