All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.bootique.jersey.jackson.JerseyJacksonModule Maven / Gradle / Ivy

Go to download

Adds JSON serialization to bootique-jersey-jakarta. Provides non-trival Jackson dependency conflicts resolution.

The newest version!
/*
 * Licensed to ObjectStyle LLC under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ObjectStyle LLC licenses
 * this file to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package io.bootique.jersey.jackson;

import com.fasterxml.jackson.databind.JsonSerializer;
import io.bootique.BaseModule;
import io.bootique.config.ConfigurationFactory;
import io.bootique.di.Binder;
import io.bootique.di.Provides;
import io.bootique.jersey.JerseyModule;

import javax.inject.Singleton;
import java.lang.reflect.Type;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

/**
 * @since 2.0
 */
public class JerseyJacksonModule extends BaseModule {

    public static JerseyJacksonModuleExtender extend(Binder binder) {
        return new JerseyJacksonModuleExtender(binder);
    }

    @Override
    public Map configs() {
        return Collections.singletonMap(configPrefix, JerseyJacksonFactory.class);
    }

    @Override
    public void configure(Binder binder) {
        JerseyModule.extend(binder).addFeature(ObjectMapperResolverFeature.class);
        JerseyJacksonModule.extend(binder).initAllExtensions();
    }

    @Singleton
    @Provides
    ObjectMapperResolverFeature provideObjectMapperResolverFeature(
            ConfigurationFactory configurationFactory,
            Set serializers) {

        ObjectMapperResolver omr = config(JerseyJacksonFactory.class, configurationFactory)
                .createObjectMapperResolver(serializers);

        return new ObjectMapperResolverFeature(omr);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy