package com.newvideo.adapter; import java.lang.reflect.Type; import net.sf.json.JSONObject; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.newvideo.domain.web.HotTypeAdmin; public class HotTypeAdminAdapter implements JsonSerializer, JsonDeserializer { // json转为对象时调用,实现JsonDeserializer接口 public HotTypeAdmin deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return null; } // 对象转为Json时调用,实现JsonSerializer接口 public JsonElement serialize(HotTypeAdmin src, Type typeOfSrc, JsonSerializationContext context) { JSONObject data = new JSONObject(); data.put("hotType", src.getHotType()); data.put("detailSystemList", src.getDetailSystemList()); JsonElement json = new JsonPrimitive(data.toString()); return json; } }