package ameba.message.internal;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import com.fasterxml.jackson.jaxrs.json.JsonEndpointConfig;
import org.glassfish.jersey.message.filtering.spi.ObjectProvider;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.core.MultivaluedMap;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

/**
 * @author icode
 */
@Singleton
public class FilteringJacksonXmlProvider extends JacksonJaxbJsonProvider {

    @Inject
    private Provider<ObjectProvider<FilterProvider>> provider;

    @Override
    protected JsonEndpointConfig _configForWriting(final ObjectMapper mapper, final Annotation[] annotations,
                                                   final Class<?> defaultView) {

        return super._configForWriting(
                JacksonEntityFilter.configFilterIntrospector(mapper)
                , annotations, defaultView);
    }

    @Override
    public void writeTo(final Object value,
                        final Class<?> type,
                        final Type genericType,
                        final Annotation[] annotations,
                        final javax.ws.rs.core.MediaType mediaType,
                        final MultivaluedMap<String, Object> httpHeaders,
                        final OutputStream entityStream) throws IOException {

        JacksonEntityFilter.setObjectWriterInjector(provider, genericType, annotations);
        super.writeTo(value, type, genericType, annotations, mediaType, httpHeaders, entityStream);
    }

}

@@ -64,26 +64,32 @@
 atabind.
-ObjectMapp
+ser.FilterProvid
 er;%0Aimpo
@@ -117,37 +117,34 @@
 son.data
-bind.ser.FilterProvid
+format.xml.XmlMapp
 er;%0Aimpo
@@ -174,20 +174,19 @@
 n.jaxrs.
-json
+xml
 .Jackson
@@ -181,36 +181,35 @@
 .xml.JacksonJaxb
-Json
+XML
 Provider;%0Aimport
@@ -241,17 +241,15 @@
 xrs.
-json.Json
+xml.XML
 Endp
@@ -651,18 +651,18 @@
 JacksonX
-ml
+ML
 Provider
@@ -681,20 +681,19 @@
 ksonJaxb
-Json
+XML
 Provider
@@ -804,12 +804,11 @@
 ted 
-Json
+XML
 Endp
@@ -842,22 +842,19 @@
 g(final 
-Object
+Xml
 Mapper m
@@ -884,33 +884,32 @@
 %5B%5D annotations,%0A
- 
                 
@@ -1029,35 +1029,40 @@
         
-JacksonEntityFilter
+(XmlMapper) JacksonUtils
 .configF
@@ -1586,20 +1586,13 @@
 kson
-EntityFilter
+Utils
 .set

add FilteringJacksonXmlProvider.java