专门分析一下fastxml.json的序列化,偶有所得,截图如下:
另一个示例
public class User {
public interface WithoutPasswordView {};
public interface WithPasswordView extends WithoutPasswordView {};
private String username;
private String password;
public User() {
}
public User(String username, String password) {
this.username = username;
this.password = password;
}
@JsonView(WithoutPasswordView.class)
public String getUsername() {
return this.username;
}
@JsonView(WithPasswordView.class)
public String getPassword() {
return this.password;
}
public static void main(String[] args) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
//创建对象
User user = new User("isea533","123456");
//序列化
ByteArrayOutputStream bos = new ByteArrayOutputStream();
objectMapper.writerWithView(User.WithoutPasswordView.class).writeValue(bos, user);
System.out.println(bos.toString());
bos.reset();
objectMapper.writerWithView(User.WithPasswordView.class).writeValue(bos, user);
System.out.println(bos.toString());
}
}
输出结果
{"username":"isea533"}
{"username":"isea533","password":"123456"}
com.fasterxml.jackson.core
jackson-core
${jackson.version}
com.fasterxml.jackson.core
jackson-databind
${jackson.version}