@JsonRawValue
/**
标记注解表示被注解的方法或字段序列化时应该包括字符串字面量的值,没有引号字符。
*/
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotation
public @interface JsonRawValue{
/**
可选的参数定义此注解是否被激活或没有
*/
boolean value() default true;
}
举例
public class RawBean {
public String name;
@JsonRawValue
public String json;
public RawBean() {
}
public RawBean(String name, String json) {
this.name = name;
this.json = json;
}
@Override
public String toString() {
return "RawBean{" +
"name='" + name + '\'' +
", json='" + json + '\'' +
'}';
}
}
@Test
public void test01() throws JsonProcessingException {
RawBean bean = new RawBean("My bean", "{\"attr\":false}");
String s = mapper.writeValueAsString(bean);
System.out.println(s);
}