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

se.fortnox.reactivewizard.client.RequestParameterSerializers Maven / Gradle / Ivy

There is a newer version: 24.6.0
Show newest version
package se.fortnox.reactivewizard.client;

import jakarta.inject.Inject;

import java.lang.reflect.ParameterizedType;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Keeps tracks of a map from class to correct RequestParameterSerializer.
 */
public class RequestParameterSerializers {

    private final Map serializers;

    @Inject
    public RequestParameterSerializers(Set requestParameterSerializers) {
        serializers = requestParameterSerializers.stream().collect(Collectors.toMap(this::getAppliedClass, Function.identity()));
    }

    public RequestParameterSerializers() {
        serializers = Collections.emptyMap();
    }

    private Class getAppliedClass(RequestParameterSerializer serializer) {
        return (Class)((ParameterizedType)serializer.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[0];
    }

    public RequestParameterSerializer getSerializer(Class type) {
        return serializers.get(type);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy