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

com.github.karsaig.approvalcrest.matcher.GsonConfiguration Maven / Gradle / Ivy

The newest version!
package com.github.karsaig.approvalcrest.matcher;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.TypeAdapterFactory;

/**
 * Configuration file for {@link GsonProvider}.
 *
 * @author Andras_Gyuro
 */
public class GsonConfiguration {

    private List typeAdapterFactories = new ArrayList<>();
    private Map> typeAdapters = new HashMap<>();
    private Map, List> typeHierarchyAdapter = new HashMap<>();

    public void addTypeAdapterFactory(TypeAdapterFactory factory) {
        typeAdapterFactories.add(factory);
    }

    public void addTypeAdapter(Type key, Object value) {
        if (typeAdapters.get(key) == null) {
            typeAdapters.put(key, new ArrayList<>());
            typeAdapters.get(key).add(value);
        } else {
            typeAdapters.get(key).add(value);
        }
    }

    public void addTypeHierarchyAdapter(Class key, Object value) {
        if (typeHierarchyAdapter.get(key) == null) {
            typeHierarchyAdapter.put(key, new ArrayList<>());
            typeHierarchyAdapter.get(key).add(value);
        } else {
            typeHierarchyAdapter.get(key).add(value);
        }
    }

    public List getTypeAdapterFactories() {
        return typeAdapterFactories;
    }

    public Map> getTypeAdapters() {
        return typeAdapters;
    }

    public Map, List> getTypeHierarchyAdapter() {
        return typeHierarchyAdapter;
    }

}