Skip to content

Commit 176106d

Browse files
committed
Refactor: Correct the data types of elements within Map<String, Object> and List<Object>
1 parent a1641e4 commit 176106d

20 files changed

Lines changed: 206 additions & 50 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ChangeLog
22

3+
## 2.5.2
4+
5+
- 修改: 正确 `Map<String, Object>` 以及 `List<Object>` 内的元素类型
6+
37
## 2.5.0
48

59
- 新增: 响应签名验签

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mavenCentral
3838
<dependency>
3939
<groupId>com.pingxx</groupId>
4040
<artifactId>pingpp-java</artifactId>
41-
<version>2.4.1</version>
41+
<version>2.5.2</version>
4242
<type>jar</type>
4343
</dependency>
4444
```
@@ -56,7 +56,7 @@ repositories {
5656
安装 Ping++ SDK
5757

5858
```
59-
implementation 'com.pingxx:pingpp-java:2.4.1'
59+
implementation 'com.pingxx:pingpp-java:2.5.2'
6060
```
6161

6262
## 初始化

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.5.0
1+
2.5.2

build.gradle

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,3 @@ allprojects {
1010
}
1111
apply plugin: 'java'
1212
}
13-
14-
sourceCompatibility = 1.8
15-
targetCompatibility = 1.8
16-
17-
dependencies {
18-
implementation 'com.google.code.gson:gson:2.10'
19-
implementation 'commons-codec:commons-codec:1.17.0'
20-
21-
testImplementation 'junit:junit:4.13.2'
22-
}

example/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies {
77
// 方法 1. 本地文件系统依赖
88
// implementation fileTree(dir: 'lib', includes: ['*jar'])
99
// 方法 2. 仓库依赖
10-
// implementation 'com.pingxx:pingpp-sdk:1.2.0'
10+
// implementation 'com.pingxx:pingpp-java:2.5.2'
1111
// 方法 3.模块依赖
1212
implementation project(':pingpp-sdk')
1313
}

pingpp-sdk/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ plugins {
1313
id "java"
1414
}
1515

16+
sourceCompatibility = 1.8
17+
targetCompatibility = 1.8
18+
1619
configurations {
1720
compileOnly {
1821
extendsFrom annotationProcessor

pingpp-sdk/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.pingxx</groupId>
77
<artifactId>pingpp-java</artifactId>
8-
<version>2.5.1</version>
8+
<version>2.5.2</version>
99
<packaging>jar</packaging>
1010

1111
<description>A Java SDK for Ping++ Payment API.</description>

pingpp-sdk/src/main/java/com/pingplusplus/Pingpp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class Pingpp {
1717
/**
1818
* version
1919
*/
20-
public static final String VERSION = "2.5.0";
20+
public static final String VERSION = "2.5.2";
2121
/**
2222
* api key
2323
*/

pingpp-sdk/src/main/java/com/pingplusplus/net/APIResource.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import com.google.gson.*;
44
import com.pingplusplus.Pingpp;
55
import com.pingplusplus.exception.*;
6-
import com.pingplusplus.exception.InvalidRequestException;
76
import com.pingplusplus.model.*;
87
import com.pingplusplus.serializer.*;
8+
import com.pingplusplus.util.GsonUtils;
99

1010
import java.io.*;
1111
import java.lang.reflect.InvocationTargetException;
@@ -41,8 +41,7 @@ protected enum RequestMethod {
4141
/**
4242
* Gson object use to transform json string to resource object
4343
*/
44-
public static final Gson GSON = new GsonBuilder()
45-
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
44+
public static final Gson GSON = GsonUtils.baseGsonBuilder()
4645
.registerTypeAdapter(Charge.class, new ChargeDeserializer())
4746
.registerTypeAdapter(RedEnvelope.class, new RedEnvelopeDeserializer())
4847
.registerTypeAdapter(Transfer.class, new TransferDeserializer())

pingpp-sdk/src/main/java/com/pingplusplus/serializer/ChargeDeserializer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.pingplusplus.serializer;
22

3-
import com.google.gson.FieldNamingPolicy;
43
import com.google.gson.Gson;
5-
import com.google.gson.GsonBuilder;
64
import com.google.gson.JsonDeserializationContext;
75
import com.google.gson.JsonDeserializer;
86
import com.google.gson.JsonElement;
@@ -11,6 +9,7 @@
119
import com.pingplusplus.model.App;
1210
import com.pingplusplus.model.Charge;
1311
import com.pingplusplus.model.ChargeRefundCollection;
12+
import com.pingplusplus.util.GsonUtils;
1413

1514
import java.lang.reflect.Type;
1615

@@ -20,40 +19,41 @@
2019
public class ChargeDeserializer implements JsonDeserializer<Charge> {
2120

2221
@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 {
2525
JsonObject chargeJson = jsonElement.getAsJsonObject();
2626
if (null != chargeJson.getAsJsonObject("credential")) {
2727
JsonObject credentialJson = chargeJson.getAsJsonObject("credential");
2828
JsonObject channelCredential;
2929
if (credentialJson.getAsJsonObject("wx") != null) {
3030
JsonObject wx = credentialJson.getAsJsonObject("wx");
31-
Long timeStamp = wx.get("timeStamp").getAsLong();
31+
long timeStamp = wx.get("timeStamp").getAsLong();
3232
wx.addProperty("timeStamp", Long.toString(timeStamp));
3333
} else if (credentialJson.getAsJsonObject("wx_pub") != null) {
3434
JsonObject wxPub = credentialJson.getAsJsonObject("wx_pub");
3535
if (null == wxPub.get("signed_data") && wxPub.get("timeStamp") != null) {
36-
Long timeStamp = wxPub.get("timeStamp").getAsLong();
36+
long timeStamp = wxPub.get("timeStamp").getAsLong();
3737
wxPub.addProperty("timeStamp", Long.toString(timeStamp));
3838
}
3939
} else if ((channelCredential = credentialJson.getAsJsonObject("bfb")) != null
4040
|| (channelCredential = credentialJson.getAsJsonObject("bfb_wap")) != null) {
4141
if (channelCredential.has("total_amount")) {
42-
Long total_amount = channelCredential.get("total_amount").getAsLong();
42+
long total_amount = channelCredential.get("total_amount").getAsLong();
4343
channelCredential.addProperty("total_amount", Long.toString(total_amount));
4444
}
4545
} else if ((channelCredential = credentialJson.getAsJsonObject("alipay")) != null
4646
|| (channelCredential = credentialJson.getAsJsonObject("alipay_wap")) != null
4747
|| (channelCredential = credentialJson.getAsJsonObject("alipay_pc_direct")) != null) {
4848
if (channelCredential.has("payment_type")) {
49-
Long paymentType = channelCredential.get("payment_type").getAsLong();
49+
long paymentType = channelCredential.get("payment_type").getAsLong();
5050
channelCredential.addProperty("payment_type", Long.toString(paymentType));
5151
}
5252
}
5353
}
5454

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())
5757
.create();
5858
JsonElement appElement = chargeJson.get("app");
5959
Charge charge = gson.fromJson(jsonElement, Charge.class);

0 commit comments

Comments
 (0)