mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Support Postgres JSONB/JSON with String - @DbJsonb String content;
This commit is contained in:
1 parent
ab047996d2
commit
583c5f74eb
10 files changed
+273
-10
No files matched your search
@@ -353,6 +353,9 @@ public final class DefaultTypeManager implements TypeManager {
|
||||
Type genericType = prop.getGenericType();
|
||||
boolean hasJacksonAnnotations = objectMapperPresent && checkJacksonAnnotations(prop);
|
||||
|
||||
if (type.equals(String.class)) {
|
||||
return ScalarTypeJsonString.typeFor(postgres, dbType);
|
||||
}
|
||||
if (type.equals(List.class)) {
|
||||
DocPropertyType docType = getDocType(genericType);
|
||||
if (!hasJacksonAnnotations && isValueTypeSimple(genericType)) {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.config.dbplatform.DbPlatformType;
|
||||
import io.ebean.config.dbplatform.ExtraDbTypes;
|
||||
import io.ebean.core.type.DataBinder;
|
||||
import io.ebean.core.type.ScalarType;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
final class ScalarTypeJsonString {
|
||||
|
||||
static final Postgres JSONB = new Postgres(ExtraDbTypes.JSONB, PostgresHelper.JSONB_TYPE);
|
||||
static final Postgres JSON = new Postgres(ExtraDbTypes.JSON, PostgresHelper.JSON_TYPE);
|
||||
|
||||
static ScalarType<?> typeFor(boolean postgres, int dbType) {
|
||||
if (postgres) {
|
||||
switch (dbType) {
|
||||
case DbPlatformType.JSONB:
|
||||
return JSONB;
|
||||
case DbPlatformType.JSON:
|
||||
return JSON;
|
||||
}
|
||||
}
|
||||
return ScalarTypeString.INSTANCE;
|
||||
}
|
||||
|
||||
private static class Postgres extends ScalarTypeStringBase {
|
||||
final String postgresType;
|
||||
|
||||
Postgres(int jdbcType, String postgresType) {
|
||||
super(true, jdbcType);
|
||||
this.postgresType = postgresType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBinder binder, String rawJson) throws SQLException {
|
||||
binder.setObject(PostgresHelper.asObject(postgresType, rawJson));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user