diff --git a/ebean-api/src/main/java/io/ebean/config/DatabaseConfig.java b/ebean-api/src/main/java/io/ebean/config/DatabaseConfig.java
index be2ac6c1f..bc3ae587f 100644
--- a/ebean-api/src/main/java/io/ebean/config/DatabaseConfig.java
+++ b/ebean-api/src/main/java/io/ebean/config/DatabaseConfig.java
@@ -193,6 +193,12 @@ public class DatabaseConfig {
*/
private JsonConfig.Include jsonInclude = JsonConfig.Include.ALL;
+ /**
+ * When true then by default DbJson beans are assumed to be dirty.
+ * I believe we want to change this default to false in the future.
+ */
+ private boolean jsonDirtyByDefault = true;
+
/**
* The database platform name. Used to imply a DatabasePlatform to use.
*/
@@ -737,6 +743,26 @@ public class DatabaseConfig {
this.jsonInclude = jsonInclude;
}
+ /**
+ * Return true if DbJson beans are assumed dirty by default.
+ *
+ * That is, when true beans that do not implement ModifyAwareType are by
+ * default assumed to be dirty and included in updates.
+ */
+ public boolean isJsonDirtyByDefault() {
+ return jsonDirtyByDefault;
+ }
+
+ /**
+ * Set to false if we want DbJson beans to not be assumed to be dirty.
+ *
+ * That is, when true beans that do not implement ModifyAwareType are by
+ * default assumed to be dirty and included in updates.
+ */
+ public void setJsonDirtyByDefault(boolean jsonDirtyByDefault) {
+ this.jsonDirtyByDefault = jsonDirtyByDefault;
+ }
+
/**
* Return the name of the Database.
*/
@@ -2909,6 +2935,7 @@ public class DatabaseConfig {
jsonInclude = p.getEnum(JsonConfig.Include.class, "jsonInclude", jsonInclude);
jsonDateTime = p.getEnum(JsonConfig.DateTime.class, "jsonDateTime", jsonDateTime);
jsonDate = p.getEnum(JsonConfig.Date.class, "jsonDate", jsonDate);
+ jsonDirtyByDefault = p.getBoolean("jsonDirtyByDefault", jsonDirtyByDefault);
runMigration = p.getBoolean("migration.run", runMigration);
ddlGenerate = p.getBoolean("ddl.generate", ddlGenerate);
@@ -3369,7 +3396,7 @@ public class DatabaseConfig {
this.loadModuleInfo = loadModuleInfo;
}
- public enum UuidVersion {
+ public enum UuidVersion {
VERSION4,
VERSION1,
VERSION1RND
diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/CheckMarkedDirty.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/CheckMarkedDirty.java
deleted file mode 100644
index 321a35fec..000000000
--- a/ebean-core/src/main/java/io/ebeaninternal/server/type/CheckMarkedDirty.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package io.ebeaninternal.server.type;
-
-import io.ebean.ModifyAwareType;
-
-/**
- * Check dirty state of json value which might be modify aware.
- */
-class CheckMarkedDirty {
-
- /**
- * Return true if the value should be considered dirty (and included in an update).
- */
- static boolean isDirty(Object value) {
- if (value instanceof ModifyAwareType) {
- ModifyAwareType modifyAware = (ModifyAwareType) value;
- if (modifyAware.isMarkedDirty()) {
- // reset the dirty state (consider not dirty after update)
- modifyAware.setMarkedDirty(false);
- return true;
- } else {
- return false;
- }
- }
- return true;
- }
-}
diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java
index 5f8a64699..82c3ff46a 100644
--- a/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java
+++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java
@@ -92,6 +92,7 @@ public final class DefaultTypeManager implements TypeManager {
private final Object objectMapper;
private final boolean objectMapperPresent;
private final boolean postgres;
+ private final TypeJsonManager jsonManager;
private final boolean offlineMigrationGeneration;
private final EnumType defaultEnumType;
@@ -131,11 +132,11 @@ public final class DefaultTypeManager implements TypeManager {
this.typeMap = new ConcurrentHashMap<>();
this.nativeMap = new ConcurrentHashMap<>();
this.logicalMap = new ConcurrentHashMap<>();
+ this.postgres = isPostgres(config.getDatabasePlatform());
this.objectMapperPresent = config.getClassLoadConfig().isJacksonObjectMapperPresent();
this.objectMapper = (objectMapperPresent) ? initObjectMapper(config) : null;
-
+ this.jsonManager = (objectMapperPresent) ? new TypeJsonManager(postgres, objectMapper, config.isJsonDirtyByDefault()) : null;
this.extraTypeFactory = new DefaultTypeFactory(config);
- this.postgres = isPostgres(config.getDatabasePlatform());
this.arrayTypeListFactory = arrayTypeListFactory(config.getDatabasePlatform());
this.arrayTypeSetFactory = arrayTypeSetFactory(config.getDatabasePlatform());
this.offlineMigrationGeneration = DbOffline.isGenerateMigration();
@@ -425,7 +426,7 @@ public final class DefaultTypeManager implements TypeManager {
if (objectMapper == null) {
throw new IllegalArgumentException("Type [" + type + "] unsupported for @DbJson mapping - Jackson ObjectMapper not present");
}
- return ScalarTypeJsonObjectMapper.createTypeFor(postgres, (AnnotatedField) prop.getJacksonField(), (ObjectMapper) objectMapper, dbType, docType);
+ return ScalarTypeJsonObjectMapper.createTypeFor(jsonManager, (AnnotatedField) prop.getJacksonField(), dbType, docType);
}
/**
diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonCollection.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonCollection.java
index a6c51ff05..e40e1a9ae 100644
--- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonCollection.java
+++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonCollection.java
@@ -61,7 +61,7 @@ abstract class ScalarTypeJsonCollection extends ScalarTypeBase implements
*/
@Override
public boolean isDirty(Object value) {
- return CheckMarkedDirty.isDirty(value);
+ return TypeJsonManager.checkIsDirty(value);
}
@Override
diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonMap.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonMap.java
index f0714c467..6dd4f900b 100644
--- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonMap.java
+++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeJsonMap.java
@@ -123,7 +123,7 @@ public abstract class ScalarTypeJsonMap extends ScalarTypeBase