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

io.tarantool.driver.mappers.MessagePackValueMapper Maven / Gradle / Ivy

Go to download

Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework

There is a newer version: 0.14.0
Show newest version
package io.tarantool.driver.mappers;

import io.tarantool.driver.mappers.converters.ValueConverter;
import org.msgpack.value.Value;
import org.msgpack.value.ValueType;

import java.util.Optional;

/**
 * Basic interface for collection of generic converters between MessagePack entities and Java objects.
 * Value converters must be added using the {@link #registerValueConverter(ValueType, Class, ValueConverter)} method
 *
 * @author Alexey Kuzin
 * @author Artyom Dubinin
 */
public interface MessagePackValueMapper {
    /**
     * Create Java object out of its MessagePack representation.
     *
     * @param v   MessagePack entity
     * @param  source MessagePack entity type
     * @param  target object type
     * @return Java object
     * @throws MessagePackValueMapperException if the corresponding conversion cannot be performed
     */
     O fromValue(V v) throws MessagePackValueMapperException;

    /**
     * Create Java object out of its MessagePack representation. Converters will be checked to match the target
     * object type.
     *
     * @param v           MessagePack entity
     * @param targetClass Java object class
     * @param          source MessagePack entity type
     * @param          target object type
     * @return Java object
     * @throws MessagePackValueMapperException if the corresponding conversion cannot be performed
     */
     O fromValue(V v, Class targetClass) throws MessagePackValueMapperException;

    /**
     * Adds a MessagePack entity converter to this mappers instance.
     *
     * @param valueType   MessagePack source type
     * @param objectClass target object class
     * @param converter   object-to-entity converter
     * @param          MessagePack's entity type that the converter accepts and/or returns
     * @param          java object's type that the converter accepts and/or returns
     * @see ValueConverter
     */
     void registerValueConverter(
        ValueType valueType, Class objectClass,
        ValueConverter converter);

     void registerValueConverterWithoutTargetClass(
        ValueType valueType, ValueConverter converter);

    /**
     * Get a converter capable of converting from the source entity class to the target class
     *
     * @param valueType   MessagePack source type
     * @param objectClass the target conversion class
     * @param          MessagePack's entity type that the converter accepts and/or returns
     * @param          java object's type that the converter accepts and/or returns
     * @return a nullable converter instance wrapped in {@code Optional}
     */
     Optional> getValueConverter(ValueType valueType, Class objectClass);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy