Skip to content

Commit 7bf7f28

Browse files
committed
修复代码格式
1 parent b68ec3a commit 7bf7f28

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed
Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,51 @@
11
package me.chanjar.weixin.mp.util.json;
22

3+
import java.lang.reflect.Type;
4+
35
import com.google.gson.JsonDeserializationContext;
46
import com.google.gson.JsonDeserializer;
57
import com.google.gson.JsonElement;
68
import com.google.gson.JsonObject;
79
import com.google.gson.JsonParseException;
810
import com.google.gson.JsonSerializationContext;
911
import com.google.gson.JsonSerializer;
12+
1013
import me.chanjar.weixin.common.util.json.GsonHelper;
1114
import me.chanjar.weixin.mp.bean.Industry;
1215
import me.chanjar.weixin.mp.bean.WxMpIndustry;
1316

14-
import java.lang.reflect.Type;
15-
1617
/**
1718
* @author miller
1819
*/
19-
public class WxMpIndustryGsonAdapter implements JsonSerializer<WxMpIndustry>, JsonDeserializer<WxMpIndustry> {
20-
@Override
21-
public JsonElement serialize(WxMpIndustry wxMpIndustry, Type type, JsonSerializationContext jsonSerializationContext) {
22-
JsonObject json = new JsonObject();
23-
json.addProperty("industry_id1", wxMpIndustry.getPrimaryIndustry().getId());
24-
json.addProperty("industry_id2", wxMpIndustry.getSecondIndustry().getId());
25-
return json;
26-
}
20+
public class WxMpIndustryGsonAdapter
21+
implements JsonSerializer<WxMpIndustry>, JsonDeserializer<WxMpIndustry> {
22+
@Override
23+
public JsonElement serialize(WxMpIndustry wxMpIndustry, Type type,
24+
JsonSerializationContext jsonSerializationContext) {
25+
JsonObject json = new JsonObject();
26+
json.addProperty("industry_id1", wxMpIndustry.getPrimaryIndustry().getId());
27+
json.addProperty("industry_id2", wxMpIndustry.getSecondIndustry().getId());
28+
return json;
29+
}
2730

28-
@Override
29-
public WxMpIndustry deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
30-
WxMpIndustry wxMpIndustry = new WxMpIndustry();
31-
JsonObject primaryIndustry = jsonElement.getAsJsonObject().get("primary_industry").getAsJsonObject();
32-
wxMpIndustry.setPrimaryIndustry(convertFromJson(primaryIndustry));
33-
JsonObject secondaryIndustry = jsonElement.getAsJsonObject().get("secondary_industry").getAsJsonObject();
34-
wxMpIndustry.setSecondIndustry(convertFromJson(secondaryIndustry));
35-
return wxMpIndustry;
36-
}
31+
@Override
32+
public WxMpIndustry deserialize(JsonElement jsonElement, Type type,
33+
JsonDeserializationContext jsonDeserializationContext)
34+
throws JsonParseException {
35+
WxMpIndustry wxMpIndustry = new WxMpIndustry();
36+
JsonObject primaryIndustry = jsonElement.getAsJsonObject()
37+
.get("primary_industry").getAsJsonObject();
38+
wxMpIndustry.setPrimaryIndustry(convertFromJson(primaryIndustry));
39+
JsonObject secondaryIndustry = jsonElement.getAsJsonObject()
40+
.get("secondary_industry").getAsJsonObject();
41+
wxMpIndustry.setSecondIndustry(convertFromJson(secondaryIndustry));
42+
return wxMpIndustry;
43+
}
3744

38-
private Industry convertFromJson(JsonObject json) {
39-
Industry industry = new Industry();
40-
industry.setFirstClass(GsonHelper.getString(json, "first_class"));
41-
industry.setSecondClass(GsonHelper.getString(json, "second_class"));
42-
return industry;
43-
}
45+
private static Industry convertFromJson(JsonObject json) {
46+
Industry industry = new Industry();
47+
industry.setFirstClass(GsonHelper.getString(json, "first_class"));
48+
industry.setSecondClass(GsonHelper.getString(json, "second_class"));
49+
return industry;
50+
}
4451
}

0 commit comments

Comments
 (0)