package com.royalnu.common.utils.json; import java.util.Collections;; import java.util.HashMap; import java.util.Map; import com.google.gson.Gson; @SuppressWarnings("unchecked") public class GsonUtil { private GsonUtil(){ } public static final Gson GSON = new Gson (); public static Map<String, Object> Object2Map(Object obj){ if(obj == null){ return Collections.emptyMap(); } return GSON.fromJson(GSON.toJson(obj), Map.class); } public static Map<String, String> Object2MapString(Object obj){ if(obj == null){ return Collections.emptyMap(); } return GSON.fromJson(GSON.toJson(obj), Map.class); } }
利用gson实现object转map,谁用谁舒服~
猜你喜欢
转载自391321729.iteye.com/blog/2348768
今日推荐
周排行