### Question:
WelcomeMessage extends WampMessage { @Override public void serialize(JsonGenerator generator) throws IOException { generator.writeNumber(getCode()); generator.writeNumber(this.sessionId); 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(); if (this.realm != null) { generator.writeStringField("realm", this.realm); } generator.writeEndObject(); } WelcomeMessage(long sessionId, List<WampRole> roles, @Nullable String realm);  WelcomeMessage(HelloMessage helloMessage, long sessionId,
			List<WampRole> roles); @SuppressWarnings("unchecked") static WelcomeMessage deserialize(JsonParser jp); @Override void serialize(JsonGenerator generator); long getSessionId(); List<WampRole> getRoles(); @Nullable String getRealm(); @Override String toString();  }### Answer:
@SuppressWarnings({ "unchecked" }) @Test public void serializeTest() throws JsonParseException, JsonMappingException, IOException { List<WampRole> roles = createRoles(); WelcomeMessage welcomeMessage = new WelcomeMessage(9129137332L, roles, "realm"); assertThat(welcomeMessage.getCode()).isEqualTo(2); assertThat(welcomeMessage.getSessionId()).isEqualTo(9129137332L); assertThat(welcomeMessage.getRoles()).isEqualTo(roles); String json = serializeToJson(welcomeMessage); String expected = "[2,9129137332,{\"roles\":{\"dealer\":{\"features\":{\"caller_identification\":true}},\"broker\":{\"features\":{\"subscriber_blackwhite_listing\":true,\"publisher_exclusion\":true,\"publisher_identification\":true,\"pattern_based_subscription\":true}}},\"realm\":\"realm\"}]"; ObjectMapper om = new ObjectMapper(); assertThat(om.readValue(json, List.class)) .isEqualTo(om.readValue(expected, List.class)); }