[英]declared custom setter but seems nothing happened with lombok
我用注解@Data
聲明了一個類,並聲明了自定義設置方法。
但是,沒有發生名為setter方法的情況。
這是構建數據。
// Build data from json string.
Type typeOfResultSet = new TypeToken<JsonResult<AntTalkList>>(){}.getType();
Gson g = new Gson();
JsonResult<AntTalkList> res = g.fromJson(jsonString, typeOfResultSet);
這是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;
}
}
我不知道如何解決這個問題。 也許使用Gson
有任何關系嗎?
根據這個問題 ,GSON不使用setter,而是直接設置字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.