mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Extract ebean-jackson-mapper module - rename ScalarTypeJsonObjectMapper to ScalarJsonJacksonMapper and move
This commit is contained in:
1 parent
d5f753d110
commit
e74e4ba532
15 files changed
+103
-12
No files matched your search
@@ -37,6 +37,12 @@
|
|||||||
<version>13.9.3-SNAPSHOT</version>
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.ebean</groupId>
|
||||||
|
<artifactId>ebean-jackson-mapper</artifactId>
|
||||||
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.ebean</groupId>
|
<groupId>io.ebean</groupId>
|
||||||
<artifactId>ebean-datasource</artifactId>
|
<artifactId>ebean-datasource</artifactId>
|
||||||
|
|||||||
@@ -122,6 +122,12 @@
|
|||||||
<version>13.9.3-SNAPSHOT</version>
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.ebean</groupId>
|
||||||
|
<artifactId>ebean-jackson-mapper</artifactId>
|
||||||
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.ebean</groupId>
|
<groupId>io.ebean</groupId>
|
||||||
<artifactId>ebean-ddl-generator</artifactId>
|
<artifactId>ebean-ddl-generator</artifactId>
|
||||||
|
|||||||
@@ -1,4 +1,13 @@
|
|||||||
package io.ebean.core.type;
|
package io.ebean.core.type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supports JSON bean properties that use something like Jackson ObjectMapper to convert between
|
||||||
|
* JSON content and the logical bean property value.
|
||||||
|
*/
|
||||||
public interface ScalarJsonMapper {
|
public interface ScalarJsonMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a ScalarType for the given JSON property.
|
||||||
|
*/
|
||||||
|
ScalarType<?> createType(ScalarJsonRequest request);
|
||||||
}
|
}
|
||||||
@@ -72,6 +72,7 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
|
|
||||||
private final PlatformArrayTypeFactory arrayTypeListFactory;
|
private final PlatformArrayTypeFactory arrayTypeListFactory;
|
||||||
private final PlatformArrayTypeFactory arrayTypeSetFactory;
|
private final PlatformArrayTypeFactory arrayTypeSetFactory;
|
||||||
|
private final ScalarJsonMapper jsonMapper;
|
||||||
private GeoTypeBinder geoTypeBinder;
|
private GeoTypeBinder geoTypeBinder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,6 +95,9 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
this.offlineMigrationGeneration = DbOffline.isGenerateMigration();
|
this.offlineMigrationGeneration = DbOffline.isGenerateMigration();
|
||||||
this.defaultEnumType = config.getDefaultEnumType();
|
this.defaultEnumType = config.getDefaultEnumType();
|
||||||
|
|
||||||
|
ServiceLoader<ScalarJsonMapper> mappers = ServiceLoader.load(ScalarJsonMapper.class);
|
||||||
|
jsonMapper = mappers.findFirst().orElse(null);
|
||||||
|
|
||||||
initialiseStandard(config);
|
initialiseStandard(config);
|
||||||
initialiseJavaTimeTypes(config);
|
initialiseJavaTimeTypes(config);
|
||||||
loadTypesFromProviders(config, objectMapper);
|
loadTypesFromProviders(config, objectMapper);
|
||||||
@@ -377,14 +381,14 @@ public final class DefaultTypeManager implements TypeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ScalarType<?> createJsonObjectMapperType(DeployBeanProperty prop, int dbType, DocPropertyType docType) {
|
private ScalarType<?> createJsonObjectMapperType(DeployBeanProperty prop, int dbType, DocPropertyType docType) {
|
||||||
if (objectMapper == null) {
|
if (jsonMapper == null) {
|
||||||
throw new IllegalArgumentException("Unsupported @DbJson mapping - Jackson ObjectMapper not present for " + prop);
|
throw new IllegalArgumentException("Unsupported @DbJson mapping - Jackson ObjectMapper not present for " + prop);
|
||||||
}
|
}
|
||||||
if (MutationDetection.DEFAULT == prop.getMutationDetection()) {
|
if (MutationDetection.DEFAULT == prop.getMutationDetection()) {
|
||||||
prop.setMutationDetection(jsonManager.mutationDetection());
|
prop.setMutationDetection(jsonManager.mutationDetection());
|
||||||
}
|
}
|
||||||
var req = new ScalarJsonRequest(jsonManager, dbType, docType, prop.getDesc().getBeanType(), prop.getMutationDetection(), prop.getName());
|
var req = new ScalarJsonRequest(jsonManager, dbType, docType, prop.getDesc().getBeanType(), prop.getMutationDetection(), prop.getName());
|
||||||
return ScalarTypeJsonObjectMapper.createTypeFor(req);
|
return jsonMapper.createType(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ module io.ebean.core {
|
|||||||
uses io.ebean.datasource.DataSourceAlertFactory;
|
uses io.ebean.datasource.DataSourceAlertFactory;
|
||||||
uses io.ebean.core.type.ExtraTypeFactory;
|
uses io.ebean.core.type.ExtraTypeFactory;
|
||||||
uses io.ebean.core.type.ScalarTypeSetFactory;
|
uses io.ebean.core.type.ScalarTypeSetFactory;
|
||||||
|
uses io.ebean.core.type.ScalarJsonMapper;
|
||||||
uses io.ebeanservice.docstore.api.DocStoreFactory;
|
uses io.ebeanservice.docstore.api.DocStoreFactory;
|
||||||
uses io.ebean.migration.auto.AutoMigrationRunner;
|
uses io.ebean.migration.auto.AutoMigrationRunner;
|
||||||
uses io.avaje.classpath.scanner.ClassPathScannerFactory;
|
uses io.avaje.classpath.scanner.ClassPathScannerFactory;
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>ebean-parent</artifactId>
|
||||||
|
<groupId>io.ebean</groupId>
|
||||||
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>ebean-jackson-mapper</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.ebean</groupId>
|
||||||
|
<artifactId>ebean-core-type</artifactId>
|
||||||
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-core</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.avaje</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>1.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package io.ebeaninternal.server.type;
|
package io.ebean.jackson.mapper;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JavaType;
|
import com.fasterxml.jackson.databind.JavaType;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package io.ebeaninternal.server.type;
|
package io.ebean.jackson.mapper;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.*;
|
import com.fasterxml.jackson.databind.*;
|
||||||
import com.fasterxml.jackson.databind.introspect.AnnotatedField;
|
import com.fasterxml.jackson.databind.introspect.AnnotatedField;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package io.ebeaninternal.server.type;
|
package io.ebean.jackson.mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper that removes whitespace from JSON. Used to normalise Postgres JSONB content.
|
* Helper that removes whitespace from JSON. Used to normalise Postgres JSONB content.
|
||||||
+7
-6
@@ -1,4 +1,4 @@
|
|||||||
package io.ebeaninternal.server.type;
|
package io.ebean.jackson.mapper;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
@@ -24,14 +24,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
/**
|
/**
|
||||||
* Supports @DbJson properties using Jackson ObjectMapper.
|
* Supports @DbJson properties using Jackson ObjectMapper.
|
||||||
*/
|
*/
|
||||||
final class ScalarTypeJsonObjectMapper {
|
public final class ScalarJsonJacksonMapper implements ScalarJsonMapper {
|
||||||
|
|
||||||
static final Map<Class<?>, AnnotatedClass> jacksonClasses = new ConcurrentHashMap<>();
|
private final Map<Class<?>, AnnotatedClass> jacksonClasses = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and return the appropriate ScalarType.
|
* Create and return the appropriate ScalarType.
|
||||||
*/
|
*/
|
||||||
static ScalarType<?> createTypeFor(ScalarJsonRequest req) {
|
@Override
|
||||||
|
public ScalarType<?> createType(ScalarJsonRequest req) {
|
||||||
AnnotatedClass annotatedClass = annotatedClass(req);
|
AnnotatedClass annotatedClass = annotatedClass(req);
|
||||||
AnnotatedField field = annotatedField(annotatedClass, req);
|
AnnotatedField field = annotatedField(annotatedClass, req);
|
||||||
if (req.mode() == MutationDetection.NONE) {
|
if (req.mode() == MutationDetection.NONE) {
|
||||||
@@ -41,7 +42,7 @@ final class ScalarTypeJsonObjectMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AnnotatedField annotatedField(AnnotatedClass annotatedClass, ScalarJsonRequest req) {
|
private AnnotatedField annotatedField(AnnotatedClass annotatedClass, ScalarJsonRequest req) {
|
||||||
for (AnnotatedField field : annotatedClass.fields()) {
|
for (AnnotatedField field : annotatedClass.fields()) {
|
||||||
if (field.getName().equals(req.name())) {
|
if (field.getName().equals(req.name())) {
|
||||||
return field;
|
return field;
|
||||||
@@ -50,7 +51,7 @@ final class ScalarTypeJsonObjectMapper {
|
|||||||
throw new IllegalStateException("AnnotatedField not found to match " + req.name());
|
throw new IllegalStateException("AnnotatedField not found to match " + req.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AnnotatedClass annotatedClass(ScalarJsonRequest req) {
|
private AnnotatedClass annotatedClass(ScalarJsonRequest req) {
|
||||||
return jacksonClasses.computeIfAbsent(req.beanType(), key -> {
|
return jacksonClasses.computeIfAbsent(req.beanType(), key -> {
|
||||||
ObjectMapper mapper = (ObjectMapper) req.manager().mapper();
|
ObjectMapper mapper = (ObjectMapper) req.manager().mapper();
|
||||||
return new DeployBeanObtainJackson(mapper, req.beanType()).obtain();
|
return new DeployBeanObtainJackson(mapper, req.beanType()).obtain();
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import io.ebean.jackson.mapper.ScalarJsonJacksonMapper;
|
||||||
|
|
||||||
|
module io.ebean.jackson.mapper {
|
||||||
|
requires io.ebean.core.type;
|
||||||
|
requires com.fasterxml.jackson.core;
|
||||||
|
requires com.fasterxml.jackson.databind;
|
||||||
|
|
||||||
|
provides io.ebean.core.type.ScalarJsonMapper with ScalarJsonJacksonMapper;
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
io.ebean.jackson.mapper.ScalarJsonJacksonMapper
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package io.ebeaninternal.server.type;
|
package io.ebean.jackson.mapper;
|
||||||
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -116,6 +116,13 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.ebean</groupId>
|
||||||
|
<artifactId>ebean-jackson-mapper</artifactId>
|
||||||
|
<version>13.9.3-SNAPSHOT</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.ebean</groupId>
|
<groupId>io.ebean</groupId>
|
||||||
<artifactId>ebean-platform-all</artifactId>
|
<artifactId>ebean-platform-all</artifactId>
|
||||||
|
|||||||
@@ -92,6 +92,7 @@
|
|||||||
<module>ebean-joda-time</module>
|
<module>ebean-joda-time</module>
|
||||||
<module>ebean-csv-reader</module>
|
<module>ebean-csv-reader</module>
|
||||||
<module>ebean-jackson-jsonnode</module>
|
<module>ebean-jackson-jsonnode</module>
|
||||||
|
<module>ebean-jackson-mapper</module>
|
||||||
<!-- <module>ebean-kotlin</module>-->
|
<!-- <module>ebean-kotlin</module>-->
|
||||||
|
|
||||||
</modules>
|
</modules>
|
||||||
|
|||||||
Reference in new issue
Block a user