@Test public void testMessageToStrippedJson() throws IOException, URISyntaxException { final Map<String, Object> container = new LinkedHashMap<>(); final Map<String, Object> messageObject = new LinkedHashMap<>(); final Map<String, Object> apnsObject = new LinkedHashMap<>(); messageObject.put("alert", "HELLO!"); messageObject.put("sound", "default"); messageObject.put("badge", 2); Map<String, Object> data = new HashMap<>(); data.put("key", "value"); data.put("key2", "value"); messageObject.put("user-data", data); apnsObject.put("action-category", "category"); apnsObject.put("content-available", "true"); messageObject.put("simple-push", "version=123"); messageObject.put("apns",apnsObject); container.put("message", messageObject); final UnifiedPushMessage unifiedPushMessage = parsePushMessage(container); String json = unifiedPushMessage.toStrippedJsonString(); Path path = Paths.get(getClass().getResource("/message-tostrippedjson.json").toURI()); String expectedJson = new String(Files.readAllBytes(path), Charset.defaultCharset()); assertEquals(expectedJson.replaceAll("\\s", ""), json); }
public String toStrippedJsonString() { try { final Map<String, Object> json = new LinkedHashMap<>(); json.put("alert", this.message.getAlert()); json.put("priority", this.message.getPriority().toString()); if (this.getMessage().getBadge()>0) { json.put("badge", Integer.toString(this.getMessage().getBadge())); } json.put("criteria", this.criteria); json.put("config", this.config); return OBJECT_MAPPER.writeValueAsString(json); } catch (JsonProcessingException e) { return "[\"invalid json\"]"; } catch (IOException e) { return "[\"invalid json\"]"; } }
UnifiedPushMessage implements Serializable { public String toStrippedJsonString() { try { final Map<String, Object> json = new LinkedHashMap<>(); json.put("alert", this.message.getAlert()); json.put("priority", this.message.getPriority().toString()); if (this.getMessage().getBadge()>0) { json.put("badge", Integer.toString(this.getMessage().getBadge())); } json.put("criteria", this.criteria); json.put("config", this.config); return OBJECT_MAPPER.writeValueAsString(json); } catch (JsonProcessingException e) { return "[\"invalid json\"]"; } catch (IOException e) { return "[\"invalid json\"]"; } } }
UnifiedPushMessage implements Serializable { public String toStrippedJsonString() { try { final Map<String, Object> json = new LinkedHashMap<>(); json.put("alert", this.message.getAlert()); json.put("priority", this.message.getPriority().toString()); if (this.getMessage().getBadge()>0) { json.put("badge", Integer.toString(this.getMessage().getBadge())); } json.put("criteria", this.criteria); json.put("config", this.config); return OBJECT_MAPPER.writeValueAsString(json); } catch (JsonProcessingException e) { return "[\"invalid json\"]"; } catch (IOException e) { return "[\"invalid json\"]"; } }  }
UnifiedPushMessage implements Serializable { public String toStrippedJsonString() { try { final Map<String, Object> json = new LinkedHashMap<>(); json.put("alert", this.message.getAlert()); json.put("priority", this.message.getPriority().toString()); if (this.getMessage().getBadge()>0) { json.put("badge", Integer.toString(this.getMessage().getBadge())); } json.put("criteria", this.criteria); json.put("config", this.config); return OBJECT_MAPPER.writeValueAsString(json); } catch (JsonProcessingException e) { return "[\"invalid json\"]"; } catch (IOException e) { return "[\"invalid json\"]"; } }  Criteria getCriteria(); void setCriteria(Criteria criteria); Config getConfig(); void setConfig(Config config); Message getMessage(); void setMessage(Message message); String toStrippedJsonString(); String toMinimizedJsonString(); String toJsonString(); @Override String toString(); }
UnifiedPushMessage implements Serializable { public String toStrippedJsonString() { try { final Map<String, Object> json = new LinkedHashMap<>(); json.put("alert", this.message.getAlert()); json.put("priority", this.message.getPriority().toString()); if (this.getMessage().getBadge()>0) { json.put("badge", Integer.toString(this.getMessage().getBadge())); } json.put("criteria", this.criteria); json.put("config", this.config); return OBJECT_MAPPER.writeValueAsString(json); } catch (JsonProcessingException e) { return "[\"invalid json\"]"; } catch (IOException e) { return "[\"invalid json\"]"; } }  Criteria getCriteria(); void setCriteria(Criteria criteria); Config getConfig(); void setConfig(Config config); Message getMessage(); void setMessage(Message message); String toStrippedJsonString(); String toMinimizedJsonString(); String toJsonString(); @Override String toString();  }