mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-24 08:57:16 +08:00
修复代码格式
This commit is contained in:
parent
b68ec3aeed
commit
7bf7f2827b
@ -1,5 +1,7 @@
|
|||||||
package me.chanjar.weixin.mp.util.json;
|
package me.chanjar.weixin.mp.util.json;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
import com.google.gson.JsonDeserializationContext;
|
import com.google.gson.JsonDeserializationContext;
|
||||||
import com.google.gson.JsonDeserializer;
|
import com.google.gson.JsonDeserializer;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
@ -7,38 +9,43 @@ import com.google.gson.JsonObject;
|
|||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.google.gson.JsonSerializationContext;
|
import com.google.gson.JsonSerializationContext;
|
||||||
import com.google.gson.JsonSerializer;
|
import com.google.gson.JsonSerializer;
|
||||||
|
|
||||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||||
import me.chanjar.weixin.mp.bean.Industry;
|
import me.chanjar.weixin.mp.bean.Industry;
|
||||||
import me.chanjar.weixin.mp.bean.WxMpIndustry;
|
import me.chanjar.weixin.mp.bean.WxMpIndustry;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author miller
|
* @author miller
|
||||||
*/
|
*/
|
||||||
public class WxMpIndustryGsonAdapter implements JsonSerializer<WxMpIndustry>, JsonDeserializer<WxMpIndustry> {
|
public class WxMpIndustryGsonAdapter
|
||||||
@Override
|
implements JsonSerializer<WxMpIndustry>, JsonDeserializer<WxMpIndustry> {
|
||||||
public JsonElement serialize(WxMpIndustry wxMpIndustry, Type type, JsonSerializationContext jsonSerializationContext) {
|
@Override
|
||||||
JsonObject json = new JsonObject();
|
public JsonElement serialize(WxMpIndustry wxMpIndustry, Type type,
|
||||||
json.addProperty("industry_id1", wxMpIndustry.getPrimaryIndustry().getId());
|
JsonSerializationContext jsonSerializationContext) {
|
||||||
json.addProperty("industry_id2", wxMpIndustry.getSecondIndustry().getId());
|
JsonObject json = new JsonObject();
|
||||||
return json;
|
json.addProperty("industry_id1", wxMpIndustry.getPrimaryIndustry().getId());
|
||||||
}
|
json.addProperty("industry_id2", wxMpIndustry.getSecondIndustry().getId());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxMpIndustry deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
|
public WxMpIndustry deserialize(JsonElement jsonElement, Type type,
|
||||||
WxMpIndustry wxMpIndustry = new WxMpIndustry();
|
JsonDeserializationContext jsonDeserializationContext)
|
||||||
JsonObject primaryIndustry = jsonElement.getAsJsonObject().get("primary_industry").getAsJsonObject();
|
throws JsonParseException {
|
||||||
wxMpIndustry.setPrimaryIndustry(convertFromJson(primaryIndustry));
|
WxMpIndustry wxMpIndustry = new WxMpIndustry();
|
||||||
JsonObject secondaryIndustry = jsonElement.getAsJsonObject().get("secondary_industry").getAsJsonObject();
|
JsonObject primaryIndustry = jsonElement.getAsJsonObject()
|
||||||
wxMpIndustry.setSecondIndustry(convertFromJson(secondaryIndustry));
|
.get("primary_industry").getAsJsonObject();
|
||||||
return wxMpIndustry;
|
wxMpIndustry.setPrimaryIndustry(convertFromJson(primaryIndustry));
|
||||||
}
|
JsonObject secondaryIndustry = jsonElement.getAsJsonObject()
|
||||||
|
.get("secondary_industry").getAsJsonObject();
|
||||||
|
wxMpIndustry.setSecondIndustry(convertFromJson(secondaryIndustry));
|
||||||
|
return wxMpIndustry;
|
||||||
|
}
|
||||||
|
|
||||||
private Industry convertFromJson(JsonObject json) {
|
private static Industry convertFromJson(JsonObject json) {
|
||||||
Industry industry = new Industry();
|
Industry industry = new Industry();
|
||||||
industry.setFirstClass(GsonHelper.getString(json, "first_class"));
|
industry.setFirstClass(GsonHelper.getString(json, "first_class"));
|
||||||
industry.setSecondClass(GsonHelper.getString(json, "second_class"));
|
industry.setSecondClass(GsonHelper.getString(json, "second_class"));
|
||||||
return industry;
|
return industry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user