PageSerializer extends StdSerializer<Page> { @Override public void serialize(Page page, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { Map<String, String> pageProperties = getPageProperties(page); jsonGenerator.writeStartObject(); for (Map.Entry<String, String> entry : pageProperties.entrySet()) { jsonGenerator.writeStringField(entry.getKey(), entry.getValue()); } jsonGenerator.writeEndObject(); } PageSerializer();  PageSerializer(Class<Page> t); @Override void serialize(Page page, JsonGenerator jsonGenerator, SerializerProvider serializerProvider);  }
@Test public void serialize() throws Exception { Page page = mock(Page.class); when(page.getName()).thenReturn(PAGE_NAME); when(page.getTitle()).thenReturn(PAGE_TITLE); when(page.getPageTitle()).thenReturn(PAGE_TITLE); when(page.getPath()).thenReturn(PAGE_PATH); when(page.getDescription()).thenReturn(PAGE_DESCRIPTION); JsonGenerator jsonGenerator = mock(JsonGenerator.class); SerializerProvider serializerProvider = mock(SerializerProvider.class); PageSerializer pageSerializer = new PageSerializer(Page.class); pageSerializer.serialize(page, jsonGenerator, serializerProvider); verify(jsonGenerator).writeStartObject(); verify(jsonGenerator).writeStringField(PageSerializer.JSON_KEY_NAME, page.getName()); verify(jsonGenerator).writeStringField(PageSerializer.JSON_KEY_TITLE, page.getTitle()); verify(jsonGenerator).writeStringField(PageSerializer.JSON_KEY_PAGE_TITLE, page.getPageTitle()); verify(jsonGenerator).writeStringField(PageSerializer.JSON_KEY_PATH, page.getPath()); verify(jsonGenerator).writeStringField(PageSerializer.JSON_KEY_DESCRIPTION, page.getDescription()); verify(jsonGenerator).writeEndObject(); verifyNoMoreInteractions(jsonGenerator); }