0

I declared a class with annotation @Data and declared custom setter.

However, it doesn't happened called setter method.

Here is for build data.

    // Build data from json string.
    Type typeOfResultSet = new TypeToken<JsonResult<AntTalkList>>(){}.getType();
        Gson g = new Gson();

    JsonResult<AntTalkList> res = g.fromJson(jsonString, typeOfResultSet);

And this is lombok @Data anotition added class.

@Data
public class TalkInfo {
    private long articleId;
    private long userId;
    private String userName; // this needs custom setter
    private String userType;
    private int last_c_seq ;
    private String title;
    private String question;
    private String dateInfo;
    private int replyCount;
    private String thumbUrl;


    public void setUserName(String userName){ // I want to call this.
        try{
            //This doesn't printed out
            System.out.println("userName");
            this.userName = URLDecoder.decode(userName, "UTF-8");
        } catch(Exception e){
            e.printStackTrace();
            this.userName = userName;
        }
    }

I don't know how to solve this problem. Maybe is there any relations using Gson ?

Minkyu Kim
  • 1,144
  • 3
  • 18
  • 43

1 Answers1

2

According to this question, GSON doesn't use setters, but sets the fields directly.

Community
  • 1
  • 1
Roel Spilker
  • 32,258
  • 10
  • 68
  • 58