gson用法

添加依赖

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
</dependency>

使用

// gson.toJson(Object); 对象转字符串 序列化
// gson.fromJson(str, Object.class); 字符串转对象
private Gson gson = new GsonBuilder().setPrettyPrinting().create();
stringRedisTemplate.boundValueOps("lisi").set(gson.toJson(employee));
String lisi = stringRedisTemplate.opsForValue().get("lisi");
gson.fromJson(lisi, Employee.class);
Last modification:March 29th, 2020 at 08:24 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment