|
1 | 1 | package com.pingplusplus.serializer; |
2 | 2 |
|
3 | | -import com.google.gson.FieldNamingPolicy; |
4 | 3 | import com.google.gson.Gson; |
5 | | -import com.google.gson.GsonBuilder; |
6 | 4 | import com.google.gson.JsonDeserializationContext; |
7 | 5 | import com.google.gson.JsonDeserializer; |
8 | 6 | import com.google.gson.JsonElement; |
|
11 | 9 | import com.pingplusplus.model.App; |
12 | 10 | import com.pingplusplus.model.Charge; |
13 | 11 | import com.pingplusplus.model.ChargeRefundCollection; |
| 12 | +import com.pingplusplus.util.GsonUtils; |
14 | 13 |
|
15 | 14 | import java.lang.reflect.Type; |
16 | 15 |
|
|
20 | 19 | public class ChargeDeserializer implements JsonDeserializer<Charge> { |
21 | 20 |
|
22 | 21 | @Override |
23 | | - public Charge deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { |
24 | | - |
| 22 | + public Charge deserialize(JsonElement jsonElement, |
| 23 | + Type type, |
| 24 | + JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { |
25 | 25 | JsonObject chargeJson = jsonElement.getAsJsonObject(); |
26 | 26 | if (null != chargeJson.getAsJsonObject("credential")) { |
27 | 27 | JsonObject credentialJson = chargeJson.getAsJsonObject("credential"); |
28 | 28 | JsonObject channelCredential; |
29 | 29 | if (credentialJson.getAsJsonObject("wx") != null) { |
30 | 30 | JsonObject wx = credentialJson.getAsJsonObject("wx"); |
31 | | - Long timeStamp = wx.get("timeStamp").getAsLong(); |
| 31 | + long timeStamp = wx.get("timeStamp").getAsLong(); |
32 | 32 | wx.addProperty("timeStamp", Long.toString(timeStamp)); |
33 | 33 | } else if (credentialJson.getAsJsonObject("wx_pub") != null) { |
34 | 34 | JsonObject wxPub = credentialJson.getAsJsonObject("wx_pub"); |
35 | 35 | if (null == wxPub.get("signed_data") && wxPub.get("timeStamp") != null) { |
36 | | - Long timeStamp = wxPub.get("timeStamp").getAsLong(); |
| 36 | + long timeStamp = wxPub.get("timeStamp").getAsLong(); |
37 | 37 | wxPub.addProperty("timeStamp", Long.toString(timeStamp)); |
38 | 38 | } |
39 | 39 | } else if ((channelCredential = credentialJson.getAsJsonObject("bfb")) != null |
40 | 40 | || (channelCredential = credentialJson.getAsJsonObject("bfb_wap")) != null) { |
41 | 41 | if (channelCredential.has("total_amount")) { |
42 | | - Long total_amount = channelCredential.get("total_amount").getAsLong(); |
| 42 | + long total_amount = channelCredential.get("total_amount").getAsLong(); |
43 | 43 | channelCredential.addProperty("total_amount", Long.toString(total_amount)); |
44 | 44 | } |
45 | 45 | } else if ((channelCredential = credentialJson.getAsJsonObject("alipay")) != null |
46 | 46 | || (channelCredential = credentialJson.getAsJsonObject("alipay_wap")) != null |
47 | 47 | || (channelCredential = credentialJson.getAsJsonObject("alipay_pc_direct")) != null) { |
48 | 48 | if (channelCredential.has("payment_type")) { |
49 | | - Long paymentType = channelCredential.get("payment_type").getAsLong(); |
| 49 | + long paymentType = channelCredential.get("payment_type").getAsLong(); |
50 | 50 | channelCredential.addProperty("payment_type", Long.toString(paymentType)); |
51 | 51 | } |
52 | 52 | } |
53 | 53 | } |
54 | 54 |
|
55 | | - Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES). |
56 | | - registerTypeAdapter(ChargeRefundCollection.class, new ChargeRefundCollectionDeserializer()) |
| 55 | + Gson gson = GsonUtils.baseGsonBuilder() |
| 56 | + .registerTypeAdapter(ChargeRefundCollection.class, new ChargeRefundCollectionDeserializer()) |
57 | 57 | .create(); |
58 | 58 | JsonElement appElement = chargeJson.get("app"); |
59 | 59 | Charge charge = gson.fromJson(jsonElement, Charge.class); |
|
0 commit comments