My class:
class ExampleBean {
private String _firstField;
private String _secondField;
}
I want to look like this:
{
"FirstField":"value",
"SecondField":"value"
}
And don't like it
{
"_FirstField":"value",
"_SecondField":"value"
}
I initialize the parser as follows:
GsonBuilder builder = new GsonBuilder();
builder.setDateFormat(DateFormat.LONG);
builder.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE);
builder.setPrettyPrinting();
set_defaultParser(builder.create());
I could see the API in the documentation from "FieldNamePolicy" as well, but I'm surprised that it doesn’t allow me to skip "_", I also know that I can use the annotation ...
@ SerializedName (" custom_naming ")
... but I don't want to write this for alllllll of my fields ...
It is very useful for me to distinguish between local variables and class fields. :( Any idea?
EDIT: There would be many obvious solutions (inheritance, gson rewrite methods, regular expressions). My question is more focused on whether there is a native gson solution or a less intrusive fix?
, FieldNamePolicy?