If this is not the case, a {@link IllegalArgumentException} is * thrown.
* - * @param clazz the class type to check and verify. + * Objects that are NULL cannot be stored. + * + * @param value the object to verify its type. */ - private void verifyValueType(final Class> clazz) { - if (simpleTypeHolder.isSimpleType(clazz)) { - return; + private void verifyValueType(final Object value) { + if(value == null) { + throw new IllegalArgumentException("Attribute of type null cannot be stored."); } - - throw new IllegalArgumentException("Attribute of type " - + clazz.getCanonicalName() + " can not be stored and must be converted."); + final Class> clazz = value.getClass(); + if (simpleTypeHolder.isSimpleType(clazz)) { + return; + } + throw new IllegalArgumentException("Attribute of type " + clazz.getCanonicalName() + " cannot be stored and must be converted."); } /** diff --git a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateTests.java b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateTests.java index 8e52c776..a2f201f2 100644 --- a/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateTests.java +++ b/src/test/java/org/springframework/data/couchbase/core/CouchbaseTemplateTests.java @@ -179,6 +179,18 @@ public class CouchbaseTemplateTests { assertNotNull(beer.getActive()); } } + + @Test + public void shouldNotSaveNull() { + final Map