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

io.castled.jdbi.ObjectSerializeArgumentFactory Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package io.castled.jdbi;

import io.castled.utils.JsonUtils;
import org.jdbi.v3.core.argument.AbstractArgumentFactory;
import org.jdbi.v3.core.argument.Argument;
import org.jdbi.v3.core.config.ConfigRegistry;

import java.sql.Types;

public class ObjectSerializeArgumentFactory extends AbstractArgumentFactory {

    public ObjectSerializeArgumentFactory() {
        super(Types.VARCHAR);
    }

    @Override
    protected Argument build(Object object, ConfigRegistry registry) {
        return (position, statement, ctx) -> statement.setString(position, JsonUtils.objectToString(object));
    }
}