Skip to content

Commit a77ca01

Browse files
author
x1a0d@n9
committed
release
1 parent 99b054a commit a77ca01

12 files changed

Lines changed: 343 additions & 503 deletions

.classpath

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
<classpath>
33
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
5-
<classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>
6-
<classpathentry kind="lib" path="lib/jackson-all-1.9.4.jar"/>
7-
<classpathentry kind="lib" path="lib/httpclient-4.2.2.jar"/>
8-
<classpathentry kind="lib" path="lib/httpcore-4.2.2.jar"/>
5+
<classpathentry kind="lib" path="lib/gson-2.2.2.jar"/>
96
<classpathentry kind="output" path="bin"/>
107
</classpath>

lib/commons-logging-1.1.1.jar

-59.3 KB
Binary file not shown.

lib/gson-2.2.2.jar

185 KB
Binary file not shown.

lib/httpclient-4.2.2.jar

-418 KB
Binary file not shown.

lib/httpcore-4.2.2.jar

-218 KB
Binary file not shown.

lib/jackson-all-1.9.4.jar

-1.07 MB
Binary file not shown.

src/cn/jpush/api/CustomMessageParams.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package cn.jpush.api;
22

3+
import java.util.HashMap;
34
import java.util.Map;
4-
import org.codehaus.jackson.map.ObjectMapper;
5+
import com.google.gson.Gson;
56

67
/*
78
* 自定义类型的消息内容
@@ -11,7 +12,7 @@ public class CustomMsgContent extends MessageParams.MsgContent {
1112
//message 里的内容类型
1213
private String contentType = "";
1314
//更多的附属信息
14-
private Map<String, Object> extra;
15+
private Map<String, Object> extra = new HashMap<String, Object>();
1516

1617
public String getContentType() {
1718
return contentType;
@@ -27,23 +28,14 @@ public void setExtra(Map<String, Object> extra) {
2728
}
2829
@Override
2930
public String toString() {
30-
StringBuffer buffer = new StringBuffer();
31-
try {
32-
buffer.append("{");
33-
buffer.append("\"message\":\"" + this.getMessage() + "\"");
34-
if (null != this.getContentType()) {
35-
buffer.append(",\"content_type\":\"" + this.getContentType() + "\"");
36-
}
37-
if (null != this.getTitle()) {
38-
buffer.append(",\"title\":\"" + this.getTitle() + "\"");
39-
}
40-
String extraJson = new ObjectMapper().writeValueAsString(this.extra);
41-
buffer.append(",\"extra\":\"" + ((null != extraJson) ? "{}":"") + "\"");
42-
buffer.append("}");
43-
} catch (Exception e) {
44-
e.printStackTrace();
45-
}
46-
return buffer.toString();
31+
Gson gson = new Gson();
32+
Map<String, String> params = new HashMap<String, String>();
33+
params.put("title", this.getTitle());
34+
params.put("message", this.getMessage());
35+
params.put("content_type", this.getContentType());
36+
params.put("extra", gson.toJson(this.getExtra()));
37+
38+
return gson.toJson(params);
4739
}
4840
}
4941

0 commit comments

Comments
 (0)