|
50 | 50 | import org.springframework.data.annotation.ReadOnlyProperty;
|
51 | 51 | import org.springframework.data.annotation.Transient;
|
52 | 52 | import org.springframework.data.annotation.TypeAlias;
|
| 53 | +import org.springframework.data.annotation.Version; |
53 | 54 | import org.springframework.data.convert.ReadingConverter;
|
54 | 55 | import org.springframework.data.convert.WritingConverter;
|
55 | 56 | import org.springframework.data.domain.Range;
|
@@ -1893,6 +1894,30 @@ void shouldNotWriteIdPropertyToDocumentSourceIfConfiguredSo() throws JSONExcepti
|
1893 | 1894 | assertEquals(expected, json, true);
|
1894 | 1895 | }
|
1895 | 1896 |
|
| 1897 | + @Test // #2364 |
| 1898 | + @DisplayName("should not write version property to document source if configured so") |
| 1899 | + void shouldNotWriteVersionPropertyToDocumentSourceIfConfiguredSo() throws JSONException { |
| 1900 | + |
| 1901 | + @Language("JSON") |
| 1902 | + var expected = """ |
| 1903 | + { |
| 1904 | + "_class": "org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverterUnitTests$DontWriteVersionToSourceEntity", |
| 1905 | + "id": "42", |
| 1906 | + "text": "some text" |
| 1907 | + } |
| 1908 | + """; |
| 1909 | + var entity = new DontWriteVersionToSourceEntity(); |
| 1910 | + entity.setId("42"); |
| 1911 | + entity.setVersion(7L); |
| 1912 | + entity.setText("some text"); |
| 1913 | + |
| 1914 | + Document document = Document.create(); |
| 1915 | + mappingElasticsearchConverter.write(entity, document); |
| 1916 | + String json = document.toJson(); |
| 1917 | + |
| 1918 | + assertEquals(expected, json, true); |
| 1919 | + } |
| 1920 | + |
1896 | 1921 | @Test // #2290
|
1897 | 1922 | @DisplayName("should respect field setting for empty properties")
|
1898 | 1923 | void shouldRespectFieldSettingForEmptyProperties() throws JSONException {
|
@@ -3004,6 +3029,43 @@ public void setText(@Nullable String text) {
|
3004 | 3029 | }
|
3005 | 3030 | }
|
3006 | 3031 |
|
| 3032 | + @org.springframework.data.elasticsearch.annotations.Document(indexName = "doesnt-matter", |
| 3033 | + storeVersionInSource = false) |
| 3034 | + static class DontWriteVersionToSourceEntity { |
| 3035 | + @Nullable private String id; |
| 3036 | + @Version |
| 3037 | + @Nullable private Long version; |
| 3038 | + @Nullable |
| 3039 | + @Field(type = FieldType.Text) private String text; |
| 3040 | + |
| 3041 | + @Nullable |
| 3042 | + public String getId() { |
| 3043 | + return id; |
| 3044 | + } |
| 3045 | + |
| 3046 | + public void setId(@Nullable String id) { |
| 3047 | + this.id = id; |
| 3048 | + } |
| 3049 | + |
| 3050 | + @Nullable |
| 3051 | + public Long getVersion() { |
| 3052 | + return version; |
| 3053 | + } |
| 3054 | + |
| 3055 | + public void setVersion(@Nullable Long version) { |
| 3056 | + this.version = version; |
| 3057 | + } |
| 3058 | + |
| 3059 | + @Nullable |
| 3060 | + public String getText() { |
| 3061 | + return text; |
| 3062 | + } |
| 3063 | + |
| 3064 | + public void setText(@Nullable String text) { |
| 3065 | + this.text = text; |
| 3066 | + } |
| 3067 | + } |
| 3068 | + |
3007 | 3069 | static class EntityWithPropertiesThatMightBeEmpty {
|
3008 | 3070 | @Nullable private String id;
|
3009 | 3071 |
|
|
0 commit comments