0

I have a REST API response object class which contains various members and their getters and setters. one of the members is

private String name;

and it is JSON'ized fine to something like

"name": "John",

However, for some reason I want to change this member to be

private Name name;

where Name is

public class Name implements Something {
    private String str;

    public Name(String name) {
        this.str = name;
    }       
    @Override
    public String toString() {
        return str;
    }
    public String getValue() {
        return str;
    }
    //... other methods
}

But now it is JSON'ized to something like
"name": {
    "value": "John"
},

is there anyway i can annotate the name field so to use the toString() so its JSON representation still looks like below?

"name": "<name.toString()>"
inor
  • 2,781
  • 2
  • 32
  • 42

1 Answers1

0

If you just wanna change the toString() result, just rewrite toString().
If you are using Json tools, for example fastjson, use @JsonProperty("")