首页>代码>spring boot+redis+cookie的微信网页授权登录实例>/jsxwsl-wx/src/main/java/cn/jsxwsl/wx/auth/utlis/JsonUtil.java
package cn.jsxwsl.wx.auth.utlis; import lombok.extern.slf4j.Slf4j; import org.codehaus.jackson.map.DeserializationConfig; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.SerializationConfig; import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; import org.springframework.util.StringUtils; import java.text.SimpleDateFormat; @Slf4j public class JsonUtil { private static ObjectMapper objectMapper = new ObjectMapper(); static { objectMapper.setSerializationInclusion(Inclusion.ALWAYS); objectMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); objectMapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); } public static <T> String obj2String(T obj) { if (obj == null) { return null; } try { return obj instanceof String ? (String) obj : objectMapper.writeValueAsString(obj); } catch (Exception e) { log.warn("Parse Object to String error", e); return null; } } public static <T> T string2Obj(String str, Class<T> clazz) { if (StringUtils.isEmpty(str) || clazz == null) { return null; } try { return clazz.equals(String.class) ? (T) str : objectMapper.readValue(str, clazz); } catch (Exception e) { log.warn("Parse String to Object error", e); return null; } } }
最近下载更多
power2016 LV3
4月19日
2206371875 LV7
2023年11月6日
libo1212 LV8
2023年6月1日
月之氏族 LV23
2023年4月26日
18120344519 LV4
2023年3月18日
唐僧洗头爱飘柔 LV22
2022年12月28日
wuying8208 LV15
2022年10月31日
crosa_Don LV18
2022年7月22日
w2lijing2 LV10
2022年5月23日
紫玉天辰 LV11
2022年2月10日
最近浏览更多
power2016 LV3
4月19日
heweimin LV12
3月20日
叁卍石 LV3
3月20日
2206371875 LV7
2023年11月6日
lzpsuifeng LV3
2023年10月13日
348835269 LV11
2023年9月27日
漫步的海星 LV4
2023年9月21日
lcqlcl LV11
2023年8月29日
Sean_admin LV7
2023年8月28日
linkage LV1
2023年7月17日