@Override
    public boolean configure(final FeatureContext context) {
        final Configuration config = context.getConfiguration();

        final String jsonFeature = CommonProperties.getValue(config.getProperties(), config.getRuntimeType(),
                InternalProperties.JSON_FEATURE, JSON_FEATURE, String.class);
        // Other JSON providers registered.
        if (!JSON_FEATURE.equalsIgnoreCase(jsonFeature)) {
            return false;
        }

        // Disable other JSON providers.
        context.property(
                PropertiesHelper.getPropertyNameForRuntime(InternalProperties.JSON_FEATURE, config.getRuntimeType()),
                JSON_FEATURE);

        if (!config.isRegistered(JacksonJsonProvider.class)) {
            ServiceLocatorUtilities.bind(locator, new AbstractBinder() {
                @Override
                protected void configure() {
                    {
                        final XmlMapper xmlMapper = new XmlMapper();
                        JacksonUtils.configureMapper(xmlMapper, mode);
                        // 不能用 jdk lambda，否则无法绑定
                        bind(new ContextResolver<XmlMapper>() {
                            @Override
                            public XmlMapper getContext(Class<?> type) {
                                return xmlMapper;
                            }
                        }).to(new TypeLiteral<ContextResolver<XmlMapper>>() {
                        });
                        bind(xmlMapper).to(XmlMapper.class).proxy(false);
                    }
                    {
                        final ObjectMapper objectMapper = new ObjectMapper();
                        JacksonUtils.configureMapper(objectMapper, mode);
                        // 不能用 jdk lambda，否则无法绑定
                        bind(new ContextResolver<ObjectMapper>() {
                            @Override
                            public ObjectMapper getContext(Class<?> type) {
                                return objectMapper;
                            }
                        }).to(new TypeLiteral<ContextResolver<ObjectMapper>>() {
                        });
                        bind(objectMapper).to(ObjectMapper.class).proxy(false);
                    }
                }
            });

            context.register(JsonProcessingExceptionMapper.class);
            if (EntityFilteringFeature.enabled(config)) {
                context.register(JacksonFilteringFeature.class);
                context.register(FilteringJacksonJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
                context.register(FilteringJacksonXMLProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
            } else {
                context.register(JacksonJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
                context.register(JacksonXMLProvider.class, MessageBodyReader.class, MessageBodyWriter.class);
            }
            Collections.addAll(HttpPatchProperties.SUPPORT_PATCH_MEDIA_TYPES,
                    MediaType.APPLICATION_JSON,
                    MediaType.APPLICATION_XML,
                    MediaType.TEXT_XML);
            return true;
        }
        return false;
    }
@ Override public boolean configure ( final FeatureContext context ) { final Configuration config = context . getConfiguration ( ) ; final String jsonFeature = CommonProperties . getValue ( config . getProperties ( ) , config . getRuntimeType ( ) , InternalProperties . JSON_FEATURE , JSON_FEATURE , String . class ) ; if ( ! JSON_FEATURE . equalsIgnoreCase ( jsonFeature ) ) { return false ; } context . property ( PropertiesHelper . getPropertyNameForRuntime ( InternalProperties . JSON_FEATURE , config . getRuntimeType ( ) ) , JSON_FEATURE ) ; if ( ! config . isRegistered ( JacksonJsonProvider . class ) ) { ServiceLocatorUtilities . bind ( locator , new AbstractBinder ( ) { @ Override protected void configure ( ) { { final XmlMapper xmlMapper = new XmlMapper ( ) ; JacksonUtils . configureMapper ( xmlMapper , mode ) ; bind ( new ContextResolver < XmlMapper > ( ) { @ Override public XmlMapper getContext ( Class < ? > type ) { return xmlMapper ; } } ) . to ( new TypeLiteral < ContextResolver < XmlMapper > > ( ) { } ) ; bind ( xmlMapper ) . to ( XmlMapper . class ) . proxy ( false ) ; } { final ObjectMapper objectMapper = new ObjectMapper ( ) ; JacksonUtils . configureMapper ( objectMapper , mode ) ; bind ( new ContextResolver < ObjectMapper > ( ) { @ Override public ObjectMapper getContext ( Class < ? > type ) { return objectMapper ; } } ) . to ( new TypeLiteral < ContextResolver < ObjectMapper > > ( ) { } ) ; bind ( objectMapper ) . to ( ObjectMapper . class ) . proxy ( false ) ; } } } ) ; context . register ( JsonProcessingExceptionMapper . class ) ; if ( EntityFilteringFeature . enabled ( config ) ) { context . register ( JacksonFilteringFeature . class ) ; context . register ( FilteringJacksonJsonProvider . class , MessageBodyReader . class , MessageBodyWriter . class ) ; context . register ( FilteringJacksonXMLProvider . class , MessageBodyReader . class , MessageBodyWriter . class ) ; } else { context . register ( JacksonJsonProvider . class , MessageBodyReader . class , MessageBodyWriter . class ) ; context . register ( JacksonXMLProvider . class , MessageBodyReader . class , MessageBodyWriter . class ) ; } Collections . addAll ( HttpPatchProperties . SUPPORT_PATCH_MEDIA_TYPES , MediaType . APPLICATION_JSON , MediaType . APPLICATION_XML , MediaType . TEXT_XML ) ; return true ; } return false ; }
{@inheritDoc}