forked from spring-attic/spring-data-aerospike
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FMWK-617 Update documentation #800
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
144c241
update documentation
agrgr 8883699
update documentation
agrgr a113381
grammar fix
agrgr 4a047dc
Merge branch 'main' into FMWK-617-update-documentation
agrgr 9caffce
Update README.adoc
agrgr 1eca9f0
Update src/main/asciidoc/reference/aerospike-object-mapping.adoc
agrgr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see documentation that talks about this change. Will that be discussed in the release notes and other markdown pages in the repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rbotzer The configuration is described in
configuration.adoc
file, it lists all properties