|
11 | 11 | */ |
12 | 12 | public class ChargeDeserializer implements JsonDeserializer<Charge> { |
13 | 13 |
|
14 | | - @Override |
15 | | - public Charge deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { |
16 | | - Gson gson = new GsonBuilder() |
17 | | - .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) |
18 | | - .registerTypeAdapter(ChargeRefundCollection.class, new ChargeRefundCollectionDeserializer()) |
19 | | - .registerTypeAdapter(PingppRawJsonObject.class, new PingppRawJsonObjectDeserializer()) |
20 | | - .create(); |
21 | | - Charge charge = gson.fromJson(jsonElement, Charge.class); |
22 | | - final JsonObject obj = jsonElement.getAsJsonObject(); |
23 | | - final JsonElement appElement = obj.get("app"); |
24 | | - if (appElement != null && appElement.isJsonObject()) { |
25 | | - App app = gson.fromJson(appElement, App.class); |
26 | | - charge.setApp(app); |
27 | | - } |
28 | | - String creStr = charge.getCredential(); |
29 | | - Type hashMapType = new TypeToken<Map<String, Object>>(){}.getType(); |
30 | | - Map<String, Object> creMap = gson.fromJson(creStr, hashMapType); |
31 | | - if (creMap.containsKey("wx")) { |
32 | | - Map<String, Object> wx = (Map<String, Object>) creMap.get("wx"); |
33 | | - wx.put("timeStamp", String.valueOf(((Double)(wx.get("timeStamp"))).longValue())); |
34 | | - charge.setCredential(creMap); |
35 | | - } |
36 | | - return charge; |
37 | | - } |
| 14 | + @Override |
| 15 | + public Charge deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { |
| 16 | + |
| 17 | + JsonObject chargeJson = jsonElement.getAsJsonObject(); |
| 18 | + if (null != chargeJson.getAsJsonObject("credential")) { |
| 19 | + JsonObject credentialJson = chargeJson.getAsJsonObject("credential"); |
| 20 | + if (null != credentialJson.getAsJsonObject("wx")) { |
| 21 | + JsonObject wx = credentialJson.getAsJsonObject("wx"); |
| 22 | + Long timeStamp = wx.get("timeStamp").getAsLong(); |
| 23 | + wx.addProperty("timeStamp", "" + timeStamp); |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).registerTypeAdapter(ChargeRefundCollection.class, new ChargeRefundCollectionDeserializer()) |
| 28 | + .registerTypeAdapter(PingppRawJsonObject.class, new PingppRawJsonObjectDeserializer()).create(); |
| 29 | + Charge charge = gson.fromJson(jsonElement, Charge.class); |
| 30 | + return charge; |
| 31 | + } |
38 | 32 | } |
0 commit comments