Skip to content

Commit

Permalink
增加对jsonExtras的空值判断 v3.4.10
Browse files Browse the repository at this point in the history
  • Loading branch information
wang110696 committed Jul 7, 2021
1 parent 7cf982f commit 33c8495
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>cn.jpush.api</groupId>
<artifactId>jpush-client</artifactId>
<version>3.4.9</version>
<version>3.4.10</version>
<packaging>jar</packaging>
<url>https://github.com/jpush/jpush-api-java-client</url>
<name>JPush API Java Client</name>
Expand Down
74 changes: 37 additions & 37 deletions src/main/java/cn/jpush/api/push/model/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

import cn.jiguang.common.utils.Preconditions;

public class Message implements PushModel {
public class Message implements PushModel {
private static final String TITLE = "title";
private static final String MSG_CONTENT = "msg_content";
private static final String CONTENT_TYPE = "content_type";
private static final String EXTRAS = "extras";

private final String title;
private final String msgContent;
private final String contentType;
Expand All @@ -26,12 +26,12 @@ public class Message implements PushModel {
private final Map<String, JsonObject> jsonExtras;
private final Map<String, JsonPrimitive> customData;

private Message(String title, String msgContent, String contentType,
Map<String, String> extras,
Map<String, Number> numberExtras,
Map<String, Boolean> booleanExtras,
Map<String, JsonObject> jsonExtras,
Map<String, JsonPrimitive> customData) {
private Message(String title, String msgContent, String contentType,
Map<String, String> extras,
Map<String, Number> numberExtras,
Map<String, Boolean> booleanExtras,
Map<String, JsonObject> jsonExtras,
Map<String, JsonPrimitive> customData) {
this.title = title;
this.msgContent = msgContent;
this.contentType = contentType;
Expand All @@ -41,15 +41,15 @@ private Message(String title, String msgContent, String contentType,
this.jsonExtras = jsonExtras;
this.customData = customData;
}

public static Builder newBuilder() {
return new Builder();
}

public static Message content(String msgContent) {
return new Builder().setMsgContent(msgContent).build();
}

@Override
public JsonElement toJSON() {
JsonObject json = new JsonObject();
Expand All @@ -62,12 +62,12 @@ public JsonElement toJSON() {
if (null != contentType) {
json.add(CONTENT_TYPE, new JsonPrimitive(contentType));
}

JsonObject extrasObject = null;
if (null != extras || null != numberExtras || null != booleanExtras || null != jsonExtras){
if (null != extras || null != numberExtras || null != booleanExtras || null != jsonExtras) {
extrasObject = new JsonObject();
}

if (null != extras) {
for (String key : extras.keySet()) {
if (extras.get(key) != null) {
Expand All @@ -93,7 +93,7 @@ public JsonElement toJSON() {
}
}

if (null != extras || null != numberExtras || null != booleanExtras) {
if (null != extras || null != numberExtras || null != booleanExtras || null != jsonExtras) {
json.add(EXTRAS, extrasObject);
}

Expand All @@ -102,7 +102,7 @@ public JsonElement toJSON() {
json.add(entry.getKey(), entry.getValue());
}
}

return json;
}

Expand All @@ -115,33 +115,33 @@ public static class Builder {
private Map<String, Boolean> booleanExtrasBuilder;
protected Map<String, JsonObject> jsonExtrasBuilder;
private Map<String, JsonPrimitive> customData;

public Builder setTitle(String title) {
this.title = title;
return this;
}

public Builder setMsgContent(String msgContent) {
this.msgContent = msgContent;
return this;
}

public Builder setContentType(String contentType) {
this.contentType = contentType;
return this;
}

public Builder addExtra(String key, String value) {
Preconditions.checkArgument(! (null == key || null == value), "Key/Value should not be null.");
Preconditions.checkArgument(!(null == key || null == value), "Key/Value should not be null.");
if (null == extrasBuilder) {
extrasBuilder = new HashMap<String, String>();
}
extrasBuilder.put(key, value);
return this;
}

public Builder addExtras(Map<String, String> extras) {
Preconditions.checkArgument(! (null == extras), "extras should not be null.");
Preconditions.checkArgument(!(null == extras), "extras should not be null.");
if (null == extrasBuilder) {
extrasBuilder = new HashMap<String, String>();
}
Expand All @@ -150,29 +150,29 @@ public Builder addExtras(Map<String, String> extras) {
}
return this;
}

public Builder addExtra(String key, Number value) {
Preconditions.checkArgument(! (null == key || null == value), "Key/Value should not be null.");
Preconditions.checkArgument(!(null == key || null == value), "Key/Value should not be null.");
if (null == numberExtrasBuilder) {
numberExtrasBuilder = new HashMap<String, Number>();
}
numberExtrasBuilder.put(key, value);
return this;
}

public Builder addExtra(String key, Boolean value) {
Preconditions.checkArgument(! (null == key || null == value), "Key/Value should not be null.");
Preconditions.checkArgument(!(null == key || null == value), "Key/Value should not be null.");
if (null == booleanExtrasBuilder) {
booleanExtrasBuilder = new HashMap<String, Boolean>();
}
booleanExtrasBuilder.put(key, value);
return this;
}

public Builder addExtra(String key, JsonObject value) {
Preconditions.checkArgument(! (null == key || null == value), "Key/Value should not be null.");
Preconditions.checkArgument(!(null == key || null == value), "Key/Value should not be null.");
if (null == jsonExtrasBuilder) {
jsonExtrasBuilder = new HashMap<String, JsonObject>();
jsonExtrasBuilder = new HashMap<String, JsonObject>();
}
jsonExtrasBuilder.put(key, value);
return this;
Expand All @@ -189,7 +189,7 @@ public Builder addCustom(Map<String, String> extras) {
}

public Builder addCustom(String key, Number value) {
Preconditions.checkArgument(! (null == key), "Key should not be null.");
Preconditions.checkArgument(!(null == key), "Key should not be null.");
if (customData == null) {
customData = new LinkedHashMap<>();
}
Expand All @@ -198,7 +198,7 @@ public Builder addCustom(String key, Number value) {
}

public Builder addCustom(String key, String value) {
Preconditions.checkArgument(! (null == key), "Key should not be null.");
Preconditions.checkArgument(!(null == key), "Key should not be null.");
if (customData == null) {
customData = new LinkedHashMap<>();
}
Expand All @@ -207,19 +207,19 @@ public Builder addCustom(String key, String value) {
}

public Builder addCustom(String key, Boolean value) {
Preconditions.checkArgument(! (null == key), "Key should not be null.");
Preconditions.checkArgument(!(null == key), "Key should not be null.");
if (customData == null) {
customData = new LinkedHashMap<>();
}
customData.put(key, new JsonPrimitive(value));
return this;
}

public Message build() {
Preconditions.checkArgument(! (null == msgContent),
Preconditions.checkArgument(!(null == msgContent),
"msgContent should be set");
return new Message(title, msgContent, contentType,
extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder,jsonExtrasBuilder, customData);
return new Message(title, msgContent, contentType,
extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder, jsonExtrasBuilder, customData);
}
}
}

0 comments on commit 33c8495

Please sign in to comment.