Search in sources :

Example 1 with HttpMessageConvertingResponseWriter

use of org.craftercms.commons.rest.HttpMessageConvertingResponseWriter in project profile by craftercms.

the class AbstractRestHandlerTestBase method createResponseWriter.

protected HttpMessageConvertingResponseWriter createResponseWriter() {
    ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean();
    factoryBean.afterPropertiesSet();
    ContentNegotiationManager contentNegotiationManager = factoryBean.getObject();
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    List<JsonSerializer<?>> serializers = new ArrayList<>();
    serializers.add(new ObjectIdSerializer());
    Map<Class<?>, JsonDeserializer<?>> deserializers = new HashMap<>();
    deserializers.put(ObjectId.class, new ObjectIdDeserializer());
    CustomSerializationObjectMapper objectMapper = new CustomSerializationObjectMapper();
    objectMapper.setSerializers(serializers);
    objectMapper.setDeserializers(deserializers);
    objectMapper.init();
    MappingJackson2HttpMessageConverter jsonMessageConverter = new MappingJackson2HttpMessageConverter();
    jsonMessageConverter.setObjectMapper(objectMapper);
    messageConverters.add(jsonMessageConverter);
    return new HttpMessageConvertingResponseWriter(contentNegotiationManager, messageConverters);
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonSerializer(com.fasterxml.jackson.databind.JsonSerializer) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) ContentNegotiationManagerFactoryBean(org.springframework.web.accept.ContentNegotiationManagerFactoryBean) HttpMessageConvertingResponseWriter(org.craftercms.commons.rest.HttpMessageConvertingResponseWriter) ContentNegotiationManager(org.springframework.web.accept.ContentNegotiationManager) ObjectIdDeserializer(org.craftercms.commons.jackson.ObjectIdDeserializer) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) CustomSerializationObjectMapper(org.craftercms.commons.jackson.CustomSerializationObjectMapper) ObjectIdSerializer(org.craftercms.commons.jackson.ObjectIdSerializer)

Aggregations

JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)1 JsonSerializer (com.fasterxml.jackson.databind.JsonSerializer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CustomSerializationObjectMapper (org.craftercms.commons.jackson.CustomSerializationObjectMapper)1 ObjectIdDeserializer (org.craftercms.commons.jackson.ObjectIdDeserializer)1 ObjectIdSerializer (org.craftercms.commons.jackson.ObjectIdSerializer)1 HttpMessageConvertingResponseWriter (org.craftercms.commons.rest.HttpMessageConvertingResponseWriter)1 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1 ContentNegotiationManager (org.springframework.web.accept.ContentNegotiationManager)1 ContentNegotiationManagerFactoryBean (org.springframework.web.accept.ContentNegotiationManagerFactoryBean)1