As the code below:
public class Main {
public class innerPerson{
private String name;
public String getName(){
return name;
In addition to existing correct answers, you can also add custom key serializers and key deserializers using Module interface (usually with SimpleModule). This allows you to externally define serialization and deserialization of keys. Either way, keys in JSON must be Strings, like others have pointed out.