@Test public void deserializeTest() throws IOException { String json = "[1, \"somerealm\", { \"roles\": { \"publisher\": {}, \"subscriber\": {} } }]"; HelloMessage helloMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(helloMessage.getCode()).isEqualTo(1); assertThat(helloMessage.getRealm()).isEqualTo("somerealm"); assertThat(helloMessage.getRoles()).containsOnly(new WampRole("publisher"), new WampRole("subscriber")); json = "[1,\"aRealm\",{\"roles\":{\"publisher\":{\"features\":{\"publisher_exclusion\":true}},\"subscriber\":{\"features\":{\"subscriber_blackwhite_listing\":true}}}}]"; helloMessage = WampMessage.deserialize(getJsonFactory(), json.getBytes(StandardCharsets.UTF_8)); assertThat(helloMessage.getCode()).isEqualTo(1); assertThat(helloMessage.getRealm()).isEqualTo("aRealm"); assertThat(helloMessage.getRoles()).containsOnlyElementsOf(createRoles()); }
@SuppressWarnings("unchecked") public static HelloMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); String realm = jp.getValueAsString(); List<WampRole> roles = new ArrayList<>(); jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } } return new HelloMessage(realm, roles); }
HelloMessage extends WampMessage { @SuppressWarnings("unchecked") public static HelloMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); String realm = jp.getValueAsString(); List<WampRole> roles = new ArrayList<>(); jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } } return new HelloMessage(realm, roles); } }
HelloMessage extends WampMessage { @SuppressWarnings("unchecked") public static HelloMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); String realm = jp.getValueAsString(); List<WampRole> roles = new ArrayList<>(); jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } } return new HelloMessage(realm, roles); } HelloMessage(@Nullable String realm, List<WampRole> roles); }
HelloMessage extends WampMessage { @SuppressWarnings("unchecked") public static HelloMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); String realm = jp.getValueAsString(); List<WampRole> roles = new ArrayList<>(); jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } } return new HelloMessage(realm, roles); } HelloMessage(@Nullable String realm, List<WampRole> roles); @SuppressWarnings("unchecked") static HelloMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); @Nullable String getRealm(); List<WampRole> getRoles(); @Override String toString(); }
HelloMessage extends WampMessage { @SuppressWarnings("unchecked") public static HelloMessage deserialize(JsonParser jp) throws IOException { jp.nextToken(); String realm = jp.getValueAsString(); List<WampRole> roles = new ArrayList<>(); jp.nextToken(); Map<String, Object> details = ParserUtil.readObject(jp); if (details != null) { Map<String, Map<String, Map<String, Boolean>>> rolesMap = (Map<String, Map<String, Map<String, Boolean>>>) details .get("roles"); for (Map.Entry<String, Map<String, Map<String, Boolean>>> entry : rolesMap .entrySet()) { WampRole wampRole = new WampRole(entry.getKey()); Map<String, Boolean> features = entry.getValue().get("features"); if (features != null) { for (String feature : features.keySet()) { wampRole.addFeature(feature); } } roles.add(wampRole); } } return new HelloMessage(realm, roles); } HelloMessage(@Nullable String realm, List<WampRole> roles); @SuppressWarnings("unchecked") static HelloMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); @Nullable String getRealm(); List<WampRole> getRoles(); @Override String toString();  }