@Test public void shouldSerializeI18nMessage() { String expectedResult = "{\"category\":\"validation\",\"message\":\"you are underage\"}"; I18nMessage message = new I18nMessage("validation", "underage"); message.setBundle(ResourceBundle.getBundle("messages")); JsonElement jsonElement = new MessageSerializer().serialize(message, mock(Type.class), mock(JsonSerializationContext.class)); assertEquals(expectedResult, jsonElement.getAsJsonObject().toString()); }
public JsonElement serialize(Message message, Type type, JsonSerializationContext context) { String json = "{category:\"%s\",message:\"%s\"}"; return new JsonParser().parse(String.format(json, message.getCategory(), message.getMessage())); }
MessageSerializer implements JsonSerializer<Message> { public JsonElement serialize(Message message, Type type, JsonSerializationContext context) { String json = "{category:\"%s\",message:\"%s\"}"; return new JsonParser().parse(String.format(json, message.getCategory(), message.getMessage())); } }
MessageSerializer implements JsonSerializer<Message> { public JsonElement serialize(Message message, Type type, JsonSerializationContext context) { String json = "{category:\"%s\",message:\"%s\"}"; return new JsonParser().parse(String.format(json, message.getCategory(), message.getMessage())); }  }
MessageSerializer implements JsonSerializer<Message> { public JsonElement serialize(Message message, Type type, JsonSerializationContext context) { String json = "{category:\"%s\",message:\"%s\"}"; return new JsonParser().parse(String.format(json, message.getCategory(), message.getMessage())); }  JsonElement serialize(Message message, Type type, JsonSerializationContext context); }
MessageSerializer implements JsonSerializer<Message> { public JsonElement serialize(Message message, Type type, JsonSerializationContext context) { String json = "{category:\"%s\",message:\"%s\"}"; return new JsonParser().parse(String.format(json, message.getCategory(), message.getMessage())); }  JsonElement serialize(Message message, Type type, JsonSerializationContext context);  }