Boon - @JsonProperty
@JsonProperty 用于标记针对 json 属性使用的非标准 getter/setter 方法。
示例 - @JsonProperty
以下示例适用于@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}