[英]declared custom setter but seems nothing happened with lombok
I declared a class with annotation @Data
and declared custom setter. 我用注解@Data
声明了一个类,并声明了自定义设置方法。
However, it doesn't happened called setter method. 但是,没有发生名为setter方法的情况。
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. 这是lombok @Data
注释添加的类。
@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
? 也许使用Gson
有任何关系吗?
根据这个问题 ,GSON不使用setter,而是直接设置字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.