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

com.vladmihalcea.hibernate.type.json.JsonStringType Maven / Gradle / Ivy

There is a newer version: 2.21.1
Show newest version
package com.vladmihalcea.hibernate.type.json;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.vladmihalcea.hibernate.type.MutableDynamicParameterizedType;
import com.vladmihalcea.hibernate.type.json.internal.JsonJavaTypeDescriptor;
import com.vladmihalcea.hibernate.type.json.internal.JsonStringJdbcTypeDescriptor;
import com.vladmihalcea.hibernate.type.util.Configuration;
import com.vladmihalcea.hibernate.type.util.ObjectMapperWrapper;

import java.lang.reflect.Type;

/**
 * 

* Maps any given Java object on a JSON column type that is managed via {@link java.sql.PreparedStatement#setString(int, String)} at JDBC Driver level. *

*
    *
  • If you are using Oracle, you can use this {@link JsonStringType} to map a {@code VARCHAR2} column type storing JSON. For more details, check out this article on vladmihalcea.com. *
  • *
  • * If you are using SQL Server, you can use this {@link JsonStringType} to map an {@code NVARCHAR} column type storing JSON. For more details, check out this article on vladmihalcea.com. *
  • *
  • * If you are using MySQL, you can use this {@link JsonStringType} to map the {@code json} column type. For more details, check out this article on vladmihalcea.com. *
  • *
  • * If you are using PostgreSQL, then you should NOT use this {@link JsonStringType}. You should use {@link JsonBinaryType} instead. For more details, check out this article on vladmihalcea.com. *
  • *
*

* If you want to use a more portable Hibernate Type that can work on Oracle, SQL Server, PostgreSQL, MySQL, or H2 without any configuration changes, then you should use the {@link JsonType} instead. *

* * @author Vlad Mihalcea */ public class JsonStringType extends MutableDynamicParameterizedType { public static final JsonStringType INSTANCE = new JsonStringType(); public JsonStringType() { super( Object.class, JsonStringJdbcTypeDescriptor.INSTANCE, new JsonJavaTypeDescriptor(Configuration.INSTANCE.getObjectMapperWrapper()) ); } public JsonStringType(Type javaType) { super( Object.class, JsonStringJdbcTypeDescriptor.INSTANCE, new JsonJavaTypeDescriptor(Configuration.INSTANCE.getObjectMapperWrapper(), javaType) ); } public JsonStringType(Configuration configuration) { super( Object.class, JsonStringJdbcTypeDescriptor.INSTANCE, new JsonJavaTypeDescriptor(configuration.getObjectMapperWrapper()) ); } public JsonStringType(org.hibernate.type.spi.TypeBootstrapContext typeBootstrapContext) { this(new Configuration(typeBootstrapContext.getConfigurationSettings())); } public JsonStringType(ObjectMapper objectMapper) { super( Object.class, JsonStringJdbcTypeDescriptor.INSTANCE, new JsonJavaTypeDescriptor(new ObjectMapperWrapper(objectMapper)) ); } public JsonStringType(ObjectMapperWrapper objectMapperWrapper) { super( Object.class, JsonStringJdbcTypeDescriptor.INSTANCE, new JsonJavaTypeDescriptor(objectMapperWrapper) ); } public JsonStringType(ObjectMapper objectMapper, Type javaType) { super( Object.class, JsonStringJdbcTypeDescriptor.INSTANCE, new JsonJavaTypeDescriptor(new ObjectMapperWrapper(objectMapper), javaType) ); } public JsonStringType(ObjectMapperWrapper objectMapperWrapper, Type javaType) { super( Object.class, JsonStringJdbcTypeDescriptor.INSTANCE, new JsonJavaTypeDescriptor(objectMapperWrapper, javaType) ); } public String getName() { return "json"; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy