forked from spring-attic/spring-data-aerospike
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FMWK-617 Update documentation (#800)
--------- Co-authored-by: Ronen Botzer <[email protected]>
- Loading branch information
Showing
31 changed files
with
185 additions
and
3,359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/asciidoc/reference/aerospike-custom-converters.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
[[aerospike.custom-converters]] | ||
= Aerospike Custom Converters | ||
|
||
Spring type converters are components used to convert data between different types, particularly when interacting with databases or binding data from external sources. They facilitate seamless transformation of data, such as converting between String and database-specific types (e.g., LocalDate to DATE or String to enumerations). | ||
|
||
For more details, see link:https://docs.spring.io/spring-framework/reference/core/validation/convert.html[Spring Type Conversion]. | ||
|
||
Spring provides a set of default type converters for common conversions. Spring Data Aerospike has its own built-in converters in `DateConverters` and `AerospikeConverters` classes. | ||
|
||
However, in certain cases, custom converters are necessary to handle specific logic or custom serialization requirements. Custom converters allow developers to define precise conversion rules, ensuring data integrity and compatibility between application types and database representations. | ||
|
||
In order to add a custom converter you can leverage Spring's `Converter` SPI to implement type conversion logic and override `customConverters()` method available in `AerospikeDataConfigurationSupport`. Here is an example: | ||
|
||
[source,java] | ||
---- | ||
public class BlockingTestConfig extends AbstractAerospikeDataConfiguration { | ||
@Override | ||
protected List<Object> customConverters() { | ||
return List.of( | ||
CompositeKey.CompositeKeyToStringConverter.INSTANCE, | ||
CompositeKey.StringToCompositeKeyConverter.INSTANCE | ||
); | ||
} | ||
@Value | ||
public static class CompositeKey { | ||
String firstPart; | ||
long secondPart; | ||
@WritingConverter | ||
public enum CompositeKeyToStringConverter implements Converter<CompositeKey, String> { | ||
INSTANCE; | ||
@Override | ||
public String convert(CompositeKey source) { | ||
return source.firstPart + "::" + source.secondPart; | ||
} | ||
} | ||
@ReadingConverter | ||
public enum StringToCompositeKeyConverter implements Converter<String, CompositeKey> { | ||
INSTANCE; | ||
@Override | ||
public CompositeKey convert(String source) { | ||
String[] split = source.split("::"); | ||
return new CompositeKey(split[0], Long.parseLong(split[1])); | ||
} | ||
} | ||
} | ||
} | ||
---- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.