@@ -1,16 +1,11 @@ | |||
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; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonParseException; | |||
import com.google.gson.*; | |||
import me.chanjar.weixin.common.util.json.GsonHelper; | |||
import me.chanjar.weixin.mp.bean.WxMpCard; | |||
import java.lang.reflect.Type; | |||
/** | |||
* Created by YuJian on 15/11/11. | |||
* | |||
@@ -21,7 +16,7 @@ public class WxMpCardGsonAdapter implements JsonDeserializer<WxMpCard> { | |||
@Override | |||
public WxMpCard deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext | |||
jsonDeserializationContext) throws JsonParseException { | |||
jsonDeserializationContext) throws JsonParseException { | |||
WxMpCard card = new WxMpCard(); | |||
JsonObject jsonObject = jsonElement.getAsJsonObject(); | |||
@@ -1,18 +1,13 @@ | |||
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; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonParseException; | |||
import com.google.gson.*; | |||
import com.google.gson.reflect.TypeToken; | |||
import me.chanjar.weixin.common.util.json.GsonHelper; | |||
import me.chanjar.weixin.mp.bean.WxMpCard; | |||
import me.chanjar.weixin.mp.bean.result.WxMpCardResult; | |||
import java.lang.reflect.Type; | |||
/** | |||
* Created by YuJian on 15/11/11. | |||
* | |||
@@ -32,8 +27,8 @@ public class WxMpCardResultGsonAdapter implements JsonDeserializer<WxMpCardResul | |||
cardResult.setUserCardStatus(GsonHelper.getString(jsonObject, "user_card_status")); | |||
WxMpCard card = WxMpGsonBuilder.INSTANCE.create().fromJson(jsonObject.get("card"), | |||
new TypeToken<WxMpCard>() { | |||
}.getType()); | |||
new TypeToken<WxMpCard>() { | |||
}.getType()); | |||
cardResult.setCard(card); | |||
@@ -2,33 +2,12 @@ package me.chanjar.weixin.mp.util.json; | |||
import com.google.gson.Gson; | |||
import com.google.gson.GsonBuilder; | |||
import me.chanjar.weixin.mp.bean.WxMpCard; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpMassNews; | |||
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpMassPreviewMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; | |||
import me.chanjar.weixin.mp.bean.WxMpMassVideo; | |||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate; | |||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | |||
import me.chanjar.weixin.mp.bean.*; | |||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; | |||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; | |||
import me.chanjar.weixin.mp.bean.material.WxMediaImgUploadResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpCardResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | |||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialCountResult; | |||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialFileBatchGetResult; | |||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNewsBatchGetResult; | |||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialUploadResult; | |||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialVideoInfoResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; | |||
import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpUser; | |||
import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; | |||
import me.chanjar.weixin.mp.bean.result.WxMpUserList; | |||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||
import me.chanjar.weixin.mp.bean.material.*; | |||
import me.chanjar.weixin.mp.bean.result.*; | |||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; | |||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; | |||
@@ -10,10 +10,17 @@ import java.lang.reflect.Type; | |||
* @author miller | |||
*/ | |||
public class WxMpIndustryGsonAdapter | |||
implements JsonSerializer<WxMpTemplateIndustry>, JsonDeserializer<WxMpTemplateIndustry> { | |||
implements JsonSerializer<WxMpTemplateIndustry>, JsonDeserializer<WxMpTemplateIndustry> { | |||
private static WxMpTemplateIndustry.Industry convertFromJson(JsonObject json) { | |||
WxMpTemplateIndustry.Industry industry = new WxMpTemplateIndustry.Industry(); | |||
industry.setFirstClass(GsonHelper.getString(json, "first_class")); | |||
industry.setSecondClass(GsonHelper.getString(json, "second_class")); | |||
return industry; | |||
} | |||
@Override | |||
public JsonElement serialize(WxMpTemplateIndustry wxMpIndustry, Type type, | |||
JsonSerializationContext jsonSerializationContext) { | |||
JsonSerializationContext jsonSerializationContext) { | |||
JsonObject json = new JsonObject(); | |||
json.addProperty("industry_id1", wxMpIndustry.getPrimaryIndustry().getId()); | |||
json.addProperty("industry_id2", wxMpIndustry.getSecondIndustry().getId()); | |||
@@ -22,22 +29,15 @@ public class WxMpIndustryGsonAdapter | |||
@Override | |||
public WxMpTemplateIndustry deserialize(JsonElement jsonElement, Type type, | |||
JsonDeserializationContext jsonDeserializationContext) | |||
throws JsonParseException { | |||
JsonDeserializationContext jsonDeserializationContext) | |||
throws JsonParseException { | |||
WxMpTemplateIndustry wxMpIndustry = new WxMpTemplateIndustry(); | |||
JsonObject primaryIndustry = jsonElement.getAsJsonObject() | |||
.get("primary_industry").getAsJsonObject(); | |||
.get("primary_industry").getAsJsonObject(); | |||
wxMpIndustry.setPrimaryIndustry(convertFromJson(primaryIndustry)); | |||
JsonObject secondaryIndustry = jsonElement.getAsJsonObject() | |||
.get("secondary_industry").getAsJsonObject(); | |||
.get("secondary_industry").getAsJsonObject(); | |||
wxMpIndustry.setSecondIndustry(convertFromJson(secondaryIndustry)); | |||
return wxMpIndustry; | |||
} | |||
private static WxMpTemplateIndustry.Industry convertFromJson(JsonObject json) { | |||
WxMpTemplateIndustry.Industry industry = new WxMpTemplateIndustry.Industry(); | |||
industry.setFirstClass(GsonHelper.getString(json, "first_class")); | |||
industry.setSecondClass(GsonHelper.getString(json, "second_class")); | |||
return industry; | |||
} | |||
} |
@@ -87,7 +87,7 @@ public class WxMpKefuMessageGsonAdapter implements JsonSerializer<WxMpKefuMessag | |||
messageJson.add("wxcard", wxcard); | |||
} | |||
if (StringUtils.isNotBlank(message.getKfAccount())){ | |||
if (StringUtils.isNotBlank(message.getKfAccount())) { | |||
JsonObject newsJsonObject = new JsonObject(); | |||
newsJsonObject.addProperty("kf_account", message.getKfAccount()); | |||
messageJson.add("customservice", newsJsonObject); | |||
@@ -15,9 +15,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | |||
import java.lang.reflect.Type; | |||
/** | |||
* | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMpMassUploadResultAdapter implements JsonDeserializer<WxMpMassUploadResult> { | |||
@@ -37,5 +35,5 @@ public class WxMpMassUploadResultAdapter implements JsonDeserializer<WxMpMassUpl | |||
} | |||
return uploadResult; | |||
} | |||
} |
@@ -17,9 +17,7 @@ import me.chanjar.weixin.mp.bean.WxMpMassVideo; | |||
import java.lang.reflect.Type; | |||
/** | |||
* | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMpMassVideoAdapter implements JsonSerializer<WxMpMassVideo> { | |||
@@ -21,7 +21,7 @@ public class WxMpMaterialNewsArticleGsonAdapter implements JsonSerializer<WxMpMa | |||
JsonObject articleJson = new JsonObject(); | |||
articleJson.addProperty("thumb_media_id", article.getThumbMediaId()); | |||
articleJson.addProperty("thumb_url",article.getThumbUrl()); | |||
articleJson.addProperty("thumb_url", article.getThumbUrl()); | |||
articleJson.addProperty("title", article.getTitle()); | |||
articleJson.addProperty("content", article.getContent()); | |||
if (null != article.getAuthor()) { | |||
@@ -70,7 +70,7 @@ public class WxMpMaterialNewsArticleGsonAdapter implements JsonSerializer<WxMpMa | |||
article.setThumbMediaId(GsonHelper.getAsString(thumbMediaId)); | |||
} | |||
JsonElement thumbUrl = articleInfo.get("thumb_url"); | |||
if(thumbUrl != null && !thumbUrl.isJsonNull()) { | |||
if (thumbUrl != null && !thumbUrl.isJsonNull()) { | |||
article.setThumbUrl(GsonHelper.getAsString(thumbUrl)); | |||
} | |||
JsonElement showCoverPic = articleInfo.get("show_cover_pic"); | |||
@@ -1,21 +1,16 @@ | |||
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; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonParseException; | |||
import com.google.gson.*; | |||
import me.chanjar.weixin.common.util.json.GsonHelper; | |||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||
import java.lang.reflect.Type; | |||
public class WxMpOAuth2AccessTokenAdapter implements JsonDeserializer<WxMpOAuth2AccessToken> { | |||
@Override | |||
public WxMpOAuth2AccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws | |||
JsonParseException { | |||
JsonParseException { | |||
WxMpOAuth2AccessToken accessToken = new WxMpOAuth2AccessToken(); | |||
JsonObject accessTokenJsonObject = json.getAsJsonObject(); | |||
@@ -15,9 +15,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; | |||
import java.lang.reflect.Type; | |||
/** | |||
* | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMpSemanticQueryResultAdapter implements JsonDeserializer<WxMpSemanticQueryResult> { | |||
@@ -46,5 +44,5 @@ public class WxMpSemanticQueryResultAdapter implements JsonDeserializer<WxMpSema | |||
} | |||
return result; | |||
} | |||
} |
@@ -12,7 +12,6 @@ import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonSerializationContext; | |||
import com.google.gson.JsonSerializer; | |||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; | |||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; | |||
@@ -8,29 +8,21 @@ | |||
*/ | |||
package me.chanjar.weixin.mp.util.json; | |||
import java.lang.reflect.Type; | |||
import java.text.ParseException; | |||
import org.apache.commons.lang3.time.FastDateFormat; | |||
import com.google.gson.JsonDeserializationContext; | |||
import com.google.gson.JsonDeserializer; | |||
import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonParseException; | |||
import com.google.gson.*; | |||
import me.chanjar.weixin.common.util.json.GsonHelper; | |||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; | |||
import org.apache.commons.lang3.time.FastDateFormat; | |||
import java.lang.reflect.Type; | |||
import java.text.ParseException; | |||
/** | |||
* | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxMpUserCumulateGsonAdapter implements JsonDeserializer<WxDataCubeUserCumulate> { | |||
private static final FastDateFormat DATE_FORMAT = FastDateFormat | |||
.getInstance("yyyy-MM-dd"); | |||
.getInstance("yyyy-MM-dd"); | |||
@Override | |||
public WxDataCubeUserCumulate deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | |||
@@ -49,5 +41,5 @@ public class WxMpUserCumulateGsonAdapter implements JsonDeserializer<WxDataCubeU | |||
return cumulate; | |||
} | |||
} |
@@ -8,17 +8,12 @@ | |||
*/ | |||
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; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonParseException; | |||
import com.google.gson.*; | |||
import me.chanjar.weixin.common.util.json.GsonHelper; | |||
import me.chanjar.weixin.mp.bean.result.WxMpUser; | |||
import java.lang.reflect.Type; | |||
public class WxMpUserGsonAdapter implements JsonDeserializer<WxMpUser> { | |||
@Override | |||
@@ -43,7 +38,7 @@ public class WxMpUserGsonAdapter implements JsonDeserializer<WxMpUser> { | |||
wxMpUser.setGroupId(GsonHelper.getInteger(o, "groupid")); | |||
wxMpUser.setTagIds(GsonHelper.getIntArray(o, "tagid_list")); | |||
wxMpUser.setSexId(sexId); | |||
if(new Integer(1).equals(sexId)) { | |||
if (new Integer(1).equals(sexId)) { | |||
wxMpUser.setSex("男"); | |||
} else if (new Integer(2).equals(sexId)) { | |||
wxMpUser.setSex("女"); | |||
@@ -8,19 +8,13 @@ | |||
*/ | |||
package me.chanjar.weixin.mp.util.json; | |||
import java.lang.reflect.Type; | |||
import java.text.ParseException; | |||
import org.apache.commons.lang3.time.FastDateFormat; | |||
import com.google.gson.JsonDeserializationContext; | |||
import com.google.gson.JsonDeserializer; | |||
import com.google.gson.JsonElement; | |||
import com.google.gson.JsonObject; | |||
import com.google.gson.JsonParseException; | |||
import com.google.gson.*; | |||
import me.chanjar.weixin.common.util.json.GsonHelper; | |||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; | |||
import org.apache.commons.lang3.time.FastDateFormat; | |||
import java.lang.reflect.Type; | |||
import java.text.ParseException; | |||
/** | |||
* @author Daniel Qian | |||
@@ -28,11 +22,11 @@ import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; | |||
public class WxMpUserSummaryGsonAdapter implements JsonDeserializer<WxDataCubeUserSummary> { | |||
private static final FastDateFormat DATE_FORMAT = FastDateFormat | |||
.getInstance("yyyy-MM-dd"); | |||
.getInstance("yyyy-MM-dd"); | |||
@Override | |||
public WxDataCubeUserSummary deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) | |||
throws JsonParseException { | |||
throws JsonParseException { | |||
WxDataCubeUserSummary summary = new WxDataCubeUserSummary(); | |||
JsonObject summaryJsonObject = json.getAsJsonObject(); | |||
@@ -15,9 +15,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; | |||
import java.lang.reflect.Type; | |||
/** | |||
* | |||
* @author Daniel Qian | |||
* | |||
*/ | |||
public class WxQrCodeTicketAdapter implements JsonDeserializer<WxMpQrCodeTicket> { | |||
@@ -37,5 +35,5 @@ public class WxQrCodeTicketAdapter implements JsonDeserializer<WxMpQrCodeTicket> | |||
} | |||
return ticket; | |||
} | |||
} |