From 7bf7f2827b86d3c28f11a5b3ab1313eb64968795 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 8 Sep 2016 15:58:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mp/util/json/WxMpIndustryGsonAdapter.java | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java index 79fb5f0bb..603612499 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpIndustryGsonAdapter.java @@ -1,5 +1,7 @@ package me.chanjar.weixin.mp.util.json; +import java.lang.reflect.Type; + import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; @@ -7,38 +9,43 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; + import me.chanjar.weixin.common.util.json.GsonHelper; import me.chanjar.weixin.mp.bean.Industry; import me.chanjar.weixin.mp.bean.WxMpIndustry; -import java.lang.reflect.Type; - /** * @author miller */ -public class WxMpIndustryGsonAdapter implements JsonSerializer, JsonDeserializer { - @Override - public JsonElement serialize(WxMpIndustry wxMpIndustry, Type type, JsonSerializationContext jsonSerializationContext) { - JsonObject json = new JsonObject(); - json.addProperty("industry_id1", wxMpIndustry.getPrimaryIndustry().getId()); - json.addProperty("industry_id2", wxMpIndustry.getSecondIndustry().getId()); - return json; - } +public class WxMpIndustryGsonAdapter + implements JsonSerializer, JsonDeserializer { + @Override + public JsonElement serialize(WxMpIndustry wxMpIndustry, Type type, + JsonSerializationContext jsonSerializationContext) { + JsonObject json = new JsonObject(); + json.addProperty("industry_id1", wxMpIndustry.getPrimaryIndustry().getId()); + json.addProperty("industry_id2", wxMpIndustry.getSecondIndustry().getId()); + return json; + } - @Override - public WxMpIndustry deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - WxMpIndustry wxMpIndustry = new WxMpIndustry(); - JsonObject primaryIndustry = jsonElement.getAsJsonObject().get("primary_industry").getAsJsonObject(); - wxMpIndustry.setPrimaryIndustry(convertFromJson(primaryIndustry)); - JsonObject secondaryIndustry = jsonElement.getAsJsonObject().get("secondary_industry").getAsJsonObject(); - wxMpIndustry.setSecondIndustry(convertFromJson(secondaryIndustry)); - return wxMpIndustry; - } + @Override + public WxMpIndustry deserialize(JsonElement jsonElement, Type type, + JsonDeserializationContext jsonDeserializationContext) + throws JsonParseException { + WxMpIndustry wxMpIndustry = new WxMpIndustry(); + JsonObject primaryIndustry = jsonElement.getAsJsonObject() + .get("primary_industry").getAsJsonObject(); + wxMpIndustry.setPrimaryIndustry(convertFromJson(primaryIndustry)); + JsonObject secondaryIndustry = jsonElement.getAsJsonObject() + .get("secondary_industry").getAsJsonObject(); + wxMpIndustry.setSecondIndustry(convertFromJson(secondaryIndustry)); + return wxMpIndustry; + } - private Industry convertFromJson(JsonObject json) { - Industry industry = new Industry(); - industry.setFirstClass(GsonHelper.getString(json, "first_class")); - industry.setSecondClass(GsonHelper.getString(json, "second_class")); - return industry; - } + private static Industry convertFromJson(JsonObject json) { + Industry industry = new Industry(); + industry.setFirstClass(GsonHelper.getString(json, "first_class")); + industry.setSecondClass(GsonHelper.getString(json, "second_class")); + return industry; + } }