I have a class with the following fields and their respective getters, plus an additional method getTotalBalance
for which I don't have any field but a custom implementation.
public class demo{
private String balance;
private String blockedBalace;
private String futureBalance;
private String availableBalance;
//getters for previous fields
public String getTotalBalance(){
//something..
}
When I serialize an object of this class I get the following JSON output.
{
"balance": "12.30",
"blockedBalance":"23.45",
"futureBalance" :"56.22",
"availableBalance" :"12.30",
"totalBalance" : "34.11"
}
Even if I didn't declare a field for totalBalance
, I've got this serialized in the end. How is it possible?
"totalBalance"
is coming from, in the JSON: I assume (but I don't have an official reference/citation) that Jackson is following the JavaBeans naming standards (replace theget
, and then make theT
lowercase) to convert the method name into a JSON key. (The reverse of what getter code generators typically do.) Someone correct me if wrong?getID
becomes "id")