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

com.arangodb.internal.serde.InternalMapperProvider Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
package com.arangodb.internal.serde;

import com.arangodb.ArangoDBException;
import com.arangodb.ContentType;
import com.arangodb.shaded.fasterxml.jackson.core.JsonFactory;
import com.arangodb.shaded.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ServiceLoader;
import java.util.function.Supplier;

public interface InternalMapperProvider extends Supplier {
    Logger LOG = LoggerFactory.getLogger(InternalMapperProvider.class);

    static ObjectMapper of(final ContentType contentType) {
        String formatName;
        if (contentType == ContentType.JSON) {
            formatName = "JSON";
        } else if (contentType == ContentType.VPACK) {
            formatName = "Velocypack";
        } else {
            throw new IllegalArgumentException("Unexpected value: " + contentType);
        }

        ServiceLoader sl = ServiceLoader.load(JsonFactory.class);
        for (JsonFactory jf : sl) {
            if(formatName.equals(jf.getFormatName())){
                return new ObjectMapper(jf);
            }
            LOG.debug("Required format ({}) not supported by JsonFactory: {}", formatName, jf.getClass().getName());
        }

        throw new ArangoDBException("No JsonFactory found for content type: " + contentType);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy