diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/CustomConversions.java b/src/main/java/org/springframework/data/couchbase/core/convert/CustomConversions.java index 56705848..bef04b59 100644 --- a/src/main/java/org/springframework/data/couchbase/core/convert/CustomConversions.java +++ b/src/main/java/org/springframework/data/couchbase/core/convert/CustomConversions.java @@ -87,7 +87,7 @@ public class CustomConversions { registerConversion(converter); } - simpleTypeHolder = new SimpleTypeHolder(); + simpleTypeHolder = new SimpleTypeHolder(customSimpleTypes, true); } /** diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java b/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java index 4ea9e60d..d599750d 100644 --- a/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java +++ b/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java @@ -498,7 +498,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter if (val == null || conversions.isSimpleType(val.getClass())) { writeSimpleInternal(val, target, simpleKey); } else if (val instanceof Collection || val.getClass().isArray()) { - target.put(simpleKey, writeCollectionInternal(asCollection(val), new CouchbaseList(), type.getMapValueType())); + target.put(simpleKey, writeCollectionInternal(asCollection(val), new CouchbaseList(conversions.getSimpleTypeHolder()), type.getMapValueType())); } else { CouchbaseDocument embeddedDoc = new CouchbaseDocument(); TypeInformation valueTypeInfo = type.isMap() ? type.getMapValueType() : ClassTypeInformation.OBJECT; @@ -521,7 +521,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter * @return the created couchbase list. */ private CouchbaseList createCollection(final Collection collection, final CouchbasePersistentProperty prop) { - return writeCollectionInternal(collection, new CouchbaseList(), prop.getTypeInformation()); + return writeCollectionInternal(collection, new CouchbaseList(conversions.getSimpleTypeHolder()), prop.getTypeInformation()); } /** @@ -542,7 +542,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter if (elementType == null || conversions.isSimpleType(elementType)) { target.put(element); } else if (element instanceof Collection || elementType.isArray()) { - target.put(writeCollectionInternal(asCollection(element), new CouchbaseList(), componentType)); + target.put(writeCollectionInternal(asCollection(element), new CouchbaseList(conversions.getSimpleTypeHolder()), componentType)); } else { CouchbaseDocument embeddedDoc = new CouchbaseDocument(); writeInternal(element, embeddedDoc, componentType); diff --git a/src/main/java/org/springframework/data/couchbase/core/mapping/CouchbaseList.java b/src/main/java/org/springframework/data/couchbase/core/mapping/CouchbaseList.java index 4a9a16d3..96c67f6a 100644 --- a/src/main/java/org/springframework/data/couchbase/core/mapping/CouchbaseList.java +++ b/src/main/java/org/springframework/data/couchbase/core/mapping/CouchbaseList.java @@ -54,12 +54,34 @@ public class CouchbaseList implements CouchbaseStorable { * @param initialPayload the initial data to store. */ public CouchbaseList(final List initialPayload) { - payload = initialPayload; + this(initialPayload, null); + } + /** + * Create a new (empty) list with an existing {@link SimpleTypeHolder}. + * + * @param simpleTypeHolder context instance. + */ + public CouchbaseList(final SimpleTypeHolder simpleTypeHolder) { + this(new ArrayList(), simpleTypeHolder); + } + + /** + * Create a new list with a given payload on construction and an existing {@link SimpleTypeHolder}. + * + * @param initialPayload the initial data to store. + * @param simpleTypeHolder context instance. + */ + public CouchbaseList(final List initialPayload, final SimpleTypeHolder simpleTypeHolder) { + this.payload = initialPayload; Set> additionalTypes = new HashSet>(); additionalTypes.add(CouchbaseDocument.class); additionalTypes.add(CouchbaseList.class); - simpleTypeHolder = new SimpleTypeHolder(additionalTypes, true); + if (simpleTypeHolder != null) { + this.simpleTypeHolder = new SimpleTypeHolder(additionalTypes, simpleTypeHolder); + } else { + this.simpleTypeHolder = new SimpleTypeHolder(additionalTypes, true); + } } /**