Search in sources :

Example 1 with CustomSerializationObjectMapper

use of org.craftercms.commons.jackson.CustomSerializationObjectMapper 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)

Example 2 with CustomSerializationObjectMapper

use of org.craftercms.commons.jackson.CustomSerializationObjectMapper in project core by craftercms.

the class Dom4JDocumentJsonSerializerTest method setUpTestObjectMapper.

private void setUpTestObjectMapper() {
    Dom4jDocumentJsonSerializer serializer = new Dom4jDocumentJsonSerializer();
    List<JsonSerializer<?>> serializers = new ArrayList<>();
    serializers.add(serializer);
    objectMapper = new CustomSerializationObjectMapper();
    objectMapper.setSerializers(serializers);
    objectMapper.init();
}
Also used : ArrayList(java.util.ArrayList) Dom4jDocumentJsonSerializer(org.craftercms.core.util.json.jackson.Dom4jDocumentJsonSerializer) Dom4jDocumentJsonSerializer(org.craftercms.core.util.json.jackson.Dom4jDocumentJsonSerializer) JsonSerializer(com.fasterxml.jackson.databind.JsonSerializer) CustomSerializationObjectMapper(org.craftercms.commons.jackson.CustomSerializationObjectMapper)

Aggregations

JsonSerializer (com.fasterxml.jackson.databind.JsonSerializer)2 ArrayList (java.util.ArrayList)2 CustomSerializationObjectMapper (org.craftercms.commons.jackson.CustomSerializationObjectMapper)2 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)1 HashMap (java.util.HashMap)1 ObjectIdDeserializer (org.craftercms.commons.jackson.ObjectIdDeserializer)1 ObjectIdSerializer (org.craftercms.commons.jackson.ObjectIdSerializer)1 HttpMessageConvertingResponseWriter (org.craftercms.commons.rest.HttpMessageConvertingResponseWriter)1 Dom4jDocumentJsonSerializer (org.craftercms.core.util.json.jackson.Dom4jDocumentJsonSerializer)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