forked from PingPlusPlus/pingpp-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotify.java
More file actions
37 lines (30 loc) · 1.07 KB
/
Notify.java
File metadata and controls
37 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.pingplusplus.model;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.pingplusplus.net.APIResource;
public class Notify {
class InnerObject {
String object;
}
public static Object parseNotify(String notifyJson) {
InnerObject innerObject;
try {
innerObject = new Gson().fromJson(notifyJson, InnerObject.class);
} catch (Exception e) {
e.printStackTrace();
return null;
}
if (innerObject == null || innerObject.object == null || innerObject.object.isEmpty())
return null;
if (innerObject.object.equals("charge")) {
return APIResource.GSON.fromJson(notifyJson, Charge.class);
} else if (innerObject.object.equals("refund")) {
return new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create()
.fromJson(notifyJson, Refund.class);
}
return null;
}
}