使用 Jackson 序列化和反序列化对象,主要使用 ObjectMapper
的 2 个方法: writeValueAsString()
和 readValue()
。
Gradle 依赖
1 | dependencies { |
Json to Map
1 | ObjectMapper mapper = new ObjectMapper(); |
JsonUtil
1 | import com.fasterxml.jackson.annotation.JsonInclude; |
输出
1 | {"id":1,"username":"Alice","email":"alice@gmail.com"} |
User
1 | public class User { |