com.vladmihalcea.hibernate.type.json.JsonType Maven / Gradle / Ivy
Show all versions of hibernate-types-60 Show documentation
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.JsonJdbcTypeDescriptor;
import com.vladmihalcea.hibernate.type.util.Configuration;
import com.vladmihalcea.hibernate.type.util.ObjectMapperWrapper;
import java.lang.reflect.Type;
/**
*
* {@link JsonType} allows you to map any given JSON object (e.g., POJO, Map<String, Object>
, List<T>, JsonNode
) on any of the following database systems:
*
*
* - PostgreSQL - for both
jsonb
and json
column types
* - MySQL - for the
json
column type
* - SQL Server - for the
NVARCHAR
column type storing JSON
* - Oracle - for the
JSON
column type if you're using Oracle 21c or the VARCHAR
column type storing JSON if you're using an older Oracle version
* - H2 - for the
json
column type
*
*
* If you switch to Oracle 21c from an older version, then you should also migrate your {@code JSON} columns to the native JSON type since this binary type performs better than
* {@code VARCHAR2} or {@code BLOB} column types.
*
*
* However, if you don't want to migrate to the new {@code JSON} data type,
* then you just have to provide the column type via the JPA {@link jakarta.persistence.Column#columnDefinition()} attribute,
* like in the following example:
*
*
* {@code @Type(}JsonType.class)
* {@code @Column(}columnDefinition = "VARCHAR2")
*
*
* For more details about how to use the {@link JsonType}, check out this article on vladmihalcea.com.
*
*
* If you are using Oracle and want to store JSON objects in a BLOB
column type, then you can use the {@link JsonBlobType} instead. For more details, check out this article on vladmihalcea.com.
*
*
* Or, you can use the {@link JsonType}, but you'll have to specify the underlying column type
* using the JPA {@link jakarta.persistence.Column#columnDefinition()} attribute, like this:
*
*
* {@code @Type(}JsonType.class)
* {@code @Column(}columnDefinition = "BLOB")
*
* @author Vlad Mihalcea
*/
public class JsonType extends MutableDynamicParameterizedType