📜  Boon-@JsonProperty

📅  最后修改于: 2020-11-18 09:08:10             🧑  作者: Mango


@JsonProperty用于标记要用于json属性的非标准getter / setter方法。

示例-@JsonProperty

import org.boon.json.JsonFactory;
import org.boon.json.ObjectMapper;
import org.boon.json.annotations.JsonProperty;

public class BoonTester {
   public static void main(String args[]) {
      ObjectMapper mapper = JsonFactory.create();     
      Student student = new Student(1);  
      String jsonString = mapper.writeValueAsString(student);
      System.out.println(jsonString);    
   }
}
class Student { 
   private int id;
   Student(){}
   Student(int id){
      this.id = id;
   }
   @JsonProperty("id")
   public int getTheId() {
      return id;
   }
   @JsonProperty("id")
   public void setTheId(int id) {
      this.id = id;
   }   
}

输出

{"id":1}