- 杰克逊标注教程
- 杰克逊 - 首页
- 序列化标注
- 杰克逊 - @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}
}
广告