/**
 * Copyright (c) 2011 Toby Brain
 * 
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *  
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *  
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 */
package com.createsend.util.jersey;

import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

/**
 * An extension of the Jersey JacksonJsonProvider used to set Jackson 
 * serialisation/deserialisation properties
 */
public class JsonProvider extends JacksonJsonProvider {
    public static final DateFormat ApiDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
    @Override
    public void writeTo(Object value, Class<?> type, Type genericType,
            Annotation[] annotations, MediaType mediaType,
            MultivaluedMap<String, Object> httpHeaders,
            OutputStream entityStream) throws IOException {
        ObjectMapper mapper = locateMapper(type, mediaType);
        mapper.setSerializationInclusion(Inclusion.NON_NULL);
        
        super.writeTo(value, type, genericType, annotations, mediaType, httpHeaders,
                entityStream);
    }
    
    @Override
    public Object readFrom(Class<Object> type, Type genericType,
            Annotation[] annotations, MediaType mediaType,
            MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
            throws IOException {
        ObjectMapper mapper = locateMapper(type, mediaType);

        mapper.setDeserializationConfig(
                mapper.getDeserializationConfig()
                        .withDateFormat(ApiDateFormat)
                        .without(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES)
        );

        return super.readFrom(type, genericType, annotations, mediaType, httpHeaders,
                entityStream);
    }
}

@@ -1200,157 +1200,159 @@
 ort 
-org.codehaus.jackson.jaxrs.JacksonJsonProvider;%0D%0Aimport org.codehaus.jackson.map.DeserializationConfig;%0D%0Aimport org.codehaus.jackson.map.ObjectMap
+java.io.IOException;%0D%0Aimport java.io.InputStream;%0D%0Aimport java.io.OutputStream;%0D%0Aimport java.lang.annotation.Annotation;%0D%0Aimport java.lang.reflect.Ty
 pe
-r
 ;%0D%0Ai
@@ -1361,65 +1361,64 @@
 ort 
-org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion
+java.text.DateFormat;%0D%0Aimport java.text.SimpleDateFormat
 ;%0D%0A%0D
@@ -1499,166 +1499,166 @@
 p;%0D%0A
+%0D%0A
 import 
-java.io.IOException;%0D%0Aimport java.io.InputStream;%0D%0Aimport java.io.OutputStream;%0D%0Aimport java.lang.annotation.Annotation;%0D%0Aimport java.lang.reflect.Ty
+org.codehaus.jackson.jaxrs.JacksonJsonProvider;%0D%0Aimport org.codehaus.jackson.map.DeserializationConfig;%0D%0Aimport org.codehaus.jackson.map.ObjectMap
 pe
+r
 ;%0D%0Ai
@@ -1667,64 +1667,65 @@
 ort 
-java.text.DateFormat;%0D%0Aimport java.text.SimpleDateFormat
+org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion
 ;%0D%0A%0D
@@ -2006,20 +2006,16 @@
 :ss%22);%0D%0A
-    
 %0D%0A    @O
@@ -2855,26 +2855,24 @@
 ediaType);%0D%0A
-%0D%0A
         mapp
@@ -2882,112 +2882,8 @@
 setD
-eserializationConfig(%0D%0A                mapper.getDeserializationConfig()%0D%0A                        .withD
 ateF
@@ -2902,16 +2902,17 @@
 eFormat)
+;
 %0D%0A      
@@ -2917,32 +2917,22 @@
     
-       
-         .without
+mapper.disable
 (Des
@@ -2989,19 +2989,8 @@
 IES)
-%0D%0A        )
 ;%0D%0A%0D

Revert "CM-16551: correctly apply deserialization settings"