@Test public void serializeTest() { List<WampRole> roles = createRoles(); HelloMessage helloMessage = new HelloMessage("aRealm", roles); assertThat(helloMessage.getCode()).isEqualTo(1); assertThat(helloMessage.getRealm()).isEqualTo("aRealm"); assertThat(helloMessage.getRoles()).isEqualTo(roles); String json = serializeToJson(helloMessage); assertThat(json).isEqualTo( "[1,\"aRealm\",{\"roles\":{\"publisher\":{\"features\":{\"publisher_exclusion\":true}},\"subscriber\":{\"features\":{\"subscriber_blackwhite_listing\":true}}}}]"); }
@Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeString(this.realm); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); generator.writeEndObject(); }
HelloMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeString(this.realm); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); generator.writeEndObject(); } }
HelloMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeString(this.realm); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); generator.writeEndObject(); } HelloMessage(@Nullable String realm, List<WampRole> roles); }
HelloMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeString(this.realm); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); generator.writeEndObject(); } 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 { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeString(this.realm); generator.writeStartObject(); generator.writeObjectFieldStart("roles"); for (WampRole wampRole : this.roles) { generator.writeObjectFieldStart(wampRole.getRole()); if (wampRole.hasFeatures()) { generator.writeObjectFieldStart("features"); for (String feature : wampRole.getFeatures()) { generator.writeBooleanField(feature, true); } generator.writeEndObject(); } generator.writeEndObject(); } generator.writeEndObject(); generator.writeEndObject(); } 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();  }