Skip to content

Commit c11ec06

Browse files
spring-projectsGH-2431 - Improve converter documentation and polish related code.
Fixes spring-projects#2431.
1 parent ea2e536 commit c11ec06

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/main/asciidoc/appendix/conversions.adoc

+3-1
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,13 @@ If you need multiple converters in your application, you can add as many as you
208208
=== For specific attributes only
209209

210210
If you need conversions only for some specific attributes, we provide `@ConvertWith`.
211-
This is an annotation that can be put on attributes carrying a `Neo4jPersistentPropertyConverter` on its `converter` attribute
211+
This is an annotation that can be put on attributes of both entities (`@Node`) and relationship properties (`@RelationshipProperties`)
212+
It defines a `Neo4jPersistentPropertyConverter` via the `converter` attribute
212213
and an optional `Neo4jPersistentPropertyConverterFactory` to construct the former.
213214
With an implementation of `Neo4jPersistentPropertyConverter` all specific conversions for a given type can be addressed.
214215

215216
We provide `@DateLong` and `@DateString` as meta-annotated annotations for backward compatibility with Neo4j-OGM schemes not using native types.
217+
Those are meta annotated annotations building on the concept above.
216218

217219
[[custom.conversions.composite-properties]]
218220
==== Composite properties

src/main/java/org/springframework/data/neo4j/core/convert/ConvertWith.java

+6
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,14 @@
4949
@API(status = API.Status.STABLE, since = "6.0")
5050
public @interface ConvertWith {
5151

52+
/**
53+
* @return The converter to instantiated for converting attributes to properties and vice versa.
54+
*/
5255
Class<? extends Neo4jPersistentPropertyConverter<?>> converter() default UnsetConverter.class;
5356

57+
/**
58+
* @return An alternative to {@link #converter()}, for all the scenarios in which constructing a converter is more effort than a constructor call.
59+
*/
5460
Class<? extends Neo4jPersistentPropertyConverterFactory> converterFactory() default DefaultNeo4jPersistentPropertyConverterFactory.class;
5561

5662
/**

src/main/java/org/springframework/data/neo4j/core/schema/CompositeProperty.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.neo4j.driver.Values;
3636
import org.springframework.beans.BeanUtils;
3737
import org.springframework.core.GenericTypeResolver;
38+
import org.springframework.core.annotation.AliasFor;
3839
import org.springframework.data.neo4j.core.convert.ConvertWith;
3940
import org.springframework.data.neo4j.core.convert.Neo4jConversionService;
4041
import org.springframework.data.neo4j.core.convert.Neo4jPersistentPropertyConverter;
@@ -66,12 +67,11 @@
6667
@API(status = API.Status.STABLE, since = "6.0")
6768
public @interface CompositeProperty {
6869

69-
String UNSET = new String("");
70-
7170
/**
7271
* @return A converter that allows to store arbitrary objects as decomposed maps on nodes and relationships. The
7372
* default converter allows only maps as composite properties.
7473
*/
74+
@AliasFor(annotation = ConvertWith.class, value = "converter")
7575
Class<? extends Neo4jPersistentPropertyToMapConverter> converter() default CompositeProperty.DefaultToMapConverter.class;
7676

7777
/**

src/test/java/org/springframework/data/neo4j/integration/shared/conversion/ListPropertyConversionIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static class DomainObjectWithListOfConvertables {
171171
@CompositeProperty(converter = ListDecomposingConverter.class, delimiter = "", prefix = "someprefix")
172172
private List<SomeConvertableClass> collectedData;
173173

174-
@ConvertWith(converter = F.class)
174+
@ConvertWith(converter = SomeconvertableClassConverter.class)
175175
private List<SomeConvertableClass> anotherSet;
176176

177177
}
@@ -253,7 +253,7 @@ public List<SomeConvertableClass> compose(Map<String, Value> source,
253253
}
254254
}
255255

256-
static class F implements Neo4jPersistentPropertyConverter<List<SomeConvertableClass>> {
256+
static class SomeconvertableClassConverter implements Neo4jPersistentPropertyConverter<List<SomeConvertableClass>> {
257257

258258
@Override public Value write(List<SomeConvertableClass> source) {
259259

0 commit comments

Comments
 (0)