use of com.fasterxml.jackson.databind.ser.SerializerFactory in project spring-framework by spring-projects.
the class MappingJackson2XmlViewTests method renderWithCustomSerializerLocatedByFactory.
@Test
public void renderWithCustomSerializerLocatedByFactory() throws Exception {
SerializerFactory factory = new DelegatingSerializerFactory(null);
XmlMapper mapper = new XmlMapper();
mapper.setSerializerFactory(factory);
view.setObjectMapper(mapper);
Object bean = new TestBeanSimple();
Map<String, Object> model = new HashMap<>();
model.put("foo", bean);
view.render(model, request, response);
String result = response.getContentAsString();
assertTrue(result.length() > 0);
assertTrue(result.contains("custom</testBeanSimple>"));
validateResult();
}
use of com.fasterxml.jackson.databind.ser.SerializerFactory in project spring-framework by spring-projects.
the class MappingJackson2JsonViewTests method renderWithCustomSerializerLocatedByFactory.
@Test
public void renderWithCustomSerializerLocatedByFactory() throws Exception {
SerializerFactory factory = new DelegatingSerializerFactory(null);
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializerFactory(factory);
view.setObjectMapper(mapper);
Object bean = new TestBeanSimple();
Map<String, Object> model = new HashMap<>();
model.put("foo", bean);
model.put("bar", new TestChildBean());
view.render(model, request, response);
String result = response.getContentAsString();
assertTrue(result.length() > 0);
assertTrue(result.contains("\"foo\":{\"testBeanSimple\":\"custom\"}"));
validateResult();
}
use of com.fasterxml.jackson.databind.ser.SerializerFactory in project spring-boot by spring-projects.
the class DataSourceJsonSerializationTests method serializerFactory.
@Test
public void serializerFactory() throws Exception {
DataSource dataSource = new DataSource();
SerializerFactory factory = BeanSerializerFactory.instance.withSerializerModifier(new GenericSerializerModifier());
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializerFactory(factory);
String value = mapper.writeValueAsString(dataSource);
assertThat(value.contains("\"url\":")).isTrue();
}
use of com.fasterxml.jackson.databind.ser.SerializerFactory in project spring-boot by spring-projects.
the class ConfigurationPropertiesReportEndpoint method applySerializationModifier.
/**
* Ensure only bindable and non-cyclic bean properties are reported.
* @param mapper the object mapper
*/
private void applySerializationModifier(ObjectMapper mapper) {
SerializerFactory factory = BeanSerializerFactory.instance.withSerializerModifier(new GenericSerializerModifier());
mapper.setSerializerFactory(factory);
}
Aggregations