class Person implements Serializable{
private static final long serialVersionUID = 1L;
private String userName;
private String passWord;
private Date birthday;
}
Fastjson
Person person = new Person();
## 序列化
String jsonOutput= JSON.toJSONString(person);
## 反序列化
Person newPerson = JSON.parseObject(jsonOutput, Person.class);
Jackson
List<User> list = userService.list();
KeyValueObject<List<User>> keyValueObject = new KeyValueObject<>();
keyValueObject.setKey("1111");
keyValueObject.setLogicalExpireSeconds(12);
keyValueObject.setAccessTag(13);
keyValueObject.setDataObject(list);
ObjectMapper objectMapper = new ObjectMapper();
### 序列化
String s = objectMapper.writeValueAsString(keyValueObject);
### 反序列化
KeyValueObject<List<User>> keyValueObject1 = objectMapper.readValue(s, new TypeReference<KeyValueObject<List<User>>>() {
});
System.out.println(keyValueObject1);
KeyValueObject<List<User>> keyValueObject2 = objectMapper.readValue(s,KeyValueObject.class);
System.out.println(keyValueObject2);
Gson
Object obj = new Object();
String obstr = new Gson().toJson(object);
Object object = new Gson().fromJson(obstr);