- 傑克遜標註教程
- 傑克遜 - 首頁
- 序列化標註
- 傑克遜 - @JsonAnyGetter
- 傑克遜 - @JsonGetter
- @JsonPropertyOrder
- 傑克遜 - @JsonRawValue
- 傑克遜 - @JsonValue
- 傑克遜 - @JsonRootName
- 傑克遜 - @JsonSerialize
- 反序列化標註
- 傑克遜 - @JsonCreator
- 傑克遜 - @JacksonInject
- 傑克遜 - @JsonAnySetter
- 傑克遜 - @JsonSetter
- 傑克遜 - @JsonDeserialize
- @JsonEnumDefaultValue
- 屬性包含標註
- @JsonIgnoreProperties
- 傑克遜 - @JsonIgnore
- 傑克遜 - @JsonIgnoreType
- 傑克遜 - @JsonInclude
- 傑克遜 - @JsonAutoDetect
- 型別處理標註
- 傑克遜 - @JsonTypeInfo
- 傑克遜 - @JsonSubTypes
- 傑克遜 - @JsonTypeName
- 通用標註
- 傑克遜 - @JsonProperty
- 傑克遜 - @JsonFormat
- 傑克遜 - @JsonUnwrapped
- 傑克遜 - @JsonView
- @JsonManagedReference
- @JsonBackReference
- 傑克遜 - @JsonIdentityInfo
- 傑克遜 - @JsonFilter
- 其他
- 自定義標註
- MixIn 標註
- 停用標註
- 傑克遜標註資源
- 傑克遜 - 快速指南
- 傑克遜 - 有用資源
- 傑克遜 - 討論
傑克遜標註 - @JsonRawValue
@JsonRawValue 可序列化文字,無需轉義或任何修飾。
無 @JsonRawValue 的示例
import java.io.IOException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JacksonTester {
public static void main(String args[]){
ObjectMapper mapper = new ObjectMapper();
try {
Student student = new Student("Mark", 1, "{\"attr\":false}");
String jsonString = mapper
.writerWithDefaultPrettyPrinter()
.writeValueAsString(student);
System.out.println(jsonString);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
class Student {
private String name;
private int rollNo;
private String json;
public Student(String name, int rollNo, String json){
this.name = name;
this.rollNo = rollNo;
this.json = json;
}
public String getName(){
return name;
}
public int getRollNo(){
return rollNo;
}
public String getJson(){
return json;
}
}
輸出
{
"name" : "Mark",
"rollNo" : 1,
"json" : {\"attr\":false}
}
有 @JsonRawValue 的示例
import java.io.IOException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.annotation.JsonRawValue;
public class JacksonTester {
public static void main(String args[]){
ObjectMapper mapper = new ObjectMapper();
try {
Student student = new Student("Mark", 1, "{\"attr\":false}");
String jsonString = mapper
.writerWithDefaultPrettyPrinter()
.writeValueAsString(student);
System.out.println(jsonString);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
class Student {
private String name;
private int rollNo;
@JsonRawValue
private String json;
public Student(String name, int rollNo, String json) {
this.name = name;
this.rollNo = rollNo;
this.json = json;
}
public String getName(){
return name;
}
public int getRollNo(){
return rollNo;
}
public String getJson(){
return json;
}
}
輸出
{
"name" : "Mark",
"rollNo" : 1,
"json" : {"attr":false}
}
廣告