com.vladmihalcea.hibernate.type.json.JsonNodeBinaryType Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-types-60 Show documentation
Show all versions of hibernate-types-60 Show documentation
Hibernate ORM 6.0 extra Types
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";
}
}