|
22 | 22 | import static org.springframework.data.mongodb.core.DBObjectTestUtils.*;
|
23 | 23 | import static org.springframework.data.mongodb.test.util.IsBsonObject.*;
|
24 | 24 |
|
| 25 | +import java.time.LocalDate; |
25 | 26 | import java.util.Arrays;
|
26 | 27 | import java.util.Collections;
|
27 | 28 | import java.util.List;
|
@@ -792,6 +793,70 @@ public void mapsUpdateWithBothReadingAndWritingConverterRegistered() {
|
792 | 793 | assertThat(result, isBsonObject().containing("$set.allocation", Allocation.AVAILABLE.code));
|
793 | 794 | }
|
794 | 795 |
|
| 796 | + /** |
| 797 | + * see DATAMONGO-1251 |
| 798 | + */ |
| 799 | + @Test |
| 800 | + public void mapsNullValueCorrectlyForSimpleTypes() { |
| 801 | + |
| 802 | + Update update = new Update().set("value", null); |
| 803 | + |
| 804 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 805 | + context.getPersistentEntity(ConcreteChildClass.class)); |
| 806 | + |
| 807 | + DBObject $set = DBObjectTestUtils.getAsDBObject(mappedUpdate, "$set"); |
| 808 | + assertThat($set.containsField("value"), is(true)); |
| 809 | + assertThat($set.get("value"), nullValue()); |
| 810 | + } |
| 811 | + |
| 812 | + /** |
| 813 | + * see DATAMONGO-1251 |
| 814 | + */ |
| 815 | + @Test |
| 816 | + public void mapsNullValueCorrectlyForJava8Date() { |
| 817 | + |
| 818 | + Update update = new Update().set("date", null); |
| 819 | + |
| 820 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 821 | + context.getPersistentEntity(ClassWithJava8Date.class)); |
| 822 | + |
| 823 | + DBObject $set = DBObjectTestUtils.getAsDBObject(mappedUpdate, "$set"); |
| 824 | + assertThat($set.containsField("date"), is(true)); |
| 825 | + assertThat($set.get("value"), nullValue()); |
| 826 | + } |
| 827 | + |
| 828 | + /** |
| 829 | + * see DATAMONGO-1251 |
| 830 | + */ |
| 831 | + @Test |
| 832 | + public void mapsNullValueCorrectlyForCollectionTypes() { |
| 833 | + |
| 834 | + Update update = new Update().set("values", null); |
| 835 | + |
| 836 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 837 | + context.getPersistentEntity(ListModel.class)); |
| 838 | + |
| 839 | + DBObject $set = DBObjectTestUtils.getAsDBObject(mappedUpdate, "$set"); |
| 840 | + assertThat($set.containsField("values"), is(true)); |
| 841 | + assertThat($set.get("value"), nullValue()); |
| 842 | + } |
| 843 | + |
| 844 | + /** |
| 845 | + * see DATAMONGO-1251 |
| 846 | + */ |
| 847 | + @Test |
| 848 | + public void mapsNullValueCorrectlyForPropertyOfNestedDocument() { |
| 849 | + |
| 850 | + Update update = new Update().set("concreteValue.name", null); |
| 851 | + |
| 852 | + DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), |
| 853 | + context.getPersistentEntity(EntityWithObject.class)); |
| 854 | + |
| 855 | + DBObject $set = DBObjectTestUtils.getAsDBObject(mappedUpdate, "$set"); |
| 856 | + assertThat($set.containsField("concreteValue.name"), is(true)); |
| 857 | + assertThat($set.get("concreteValue.name"), nullValue()); |
| 858 | + } |
| 859 | + |
795 | 860 | static class DomainTypeWrappingConcreteyTypeHavingListOfInterfaceTypeAttributes {
|
796 | 861 | ListModelWrapper concreteTypeWithListAttributeOfInterfaceType;
|
797 | 862 | }
|
@@ -1061,4 +1126,9 @@ public Allocation convert(String source) {
|
1061 | 1126 | }
|
1062 | 1127 | }
|
1063 | 1128 | }
|
| 1129 | + |
| 1130 | + static class ClassWithJava8Date { |
| 1131 | + |
| 1132 | + LocalDate date; |
| 1133 | + } |
1064 | 1134 | }
|
0 commit comments