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

com.vladmihalcea.hibernate.type.json.JsonNodeBinaryType 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.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vladmihalcea.hibernate.type.MutableDynamicParameterizedType;
import com.vladmihalcea.hibernate.type.json.internal.JsonBinaryJdbcTypeDescriptor;
import com.vladmihalcea.hibernate.type.json.internal.JsonNodeJavaTypeDescriptor;
import com.vladmihalcea.hibernate.type.util.Configuration;
import com.vladmihalcea.hibernate.type.util.ObjectMapperWrapper;

/**
 * 

* Maps a Jackson {@link JsonNode} object on a JSON column type that is managed via {@link java.sql.PreparedStatement#setObject(int, Object)} at JDBC Driver level. *

*

* For instance, if you are using PostgreSQL, you can use the {@link JsonNodeBinaryType} to map both {@code jsonb} and {@code json} column types to a Jackson {@link JsonNode} object. *

*

* For more details about how to use it, 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 JsonNodeBinaryType extends MutableDynamicParameterizedType { public static final JsonNodeBinaryType INSTANCE = new JsonNodeBinaryType(); public JsonNodeBinaryType() { super( JsonNode.class, JsonBinaryJdbcTypeDescriptor.INSTANCE, new JsonNodeJavaTypeDescriptor(Configuration.INSTANCE.getObjectMapperWrapper()) ); } public JsonNodeBinaryType(Configuration configuration) { super( JsonNode.class, JsonBinaryJdbcTypeDescriptor.INSTANCE, new JsonNodeJavaTypeDescriptor(configuration.getObjectMapperWrapper()) ); } public JsonNodeBinaryType(org.hibernate.type.spi.TypeBootstrapContext typeBootstrapContext) { this(new Configuration(typeBootstrapContext.getConfigurationSettings())); } public JsonNodeBinaryType(ObjectMapper objectMapper) { super( JsonNode.class, JsonBinaryJdbcTypeDescriptor.INSTANCE, new JsonNodeJavaTypeDescriptor(new ObjectMapperWrapper(objectMapper)) ); } public JsonNodeBinaryType(ObjectMapperWrapper objectMapperWrapper) { super( JsonNode.class, JsonBinaryJdbcTypeDescriptor.INSTANCE, new JsonNodeJavaTypeDescriptor(objectMapperWrapper) ); } public String getName() { return "jsonb-node"; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy