Skip to content

Support for YearMonth Reading and Writer Converters #1720

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

Closed
cabbonizio opened this issue Apr 20, 2023 · 1 comment · Fixed by #1722 or #1723
Closed

Support for YearMonth Reading and Writer Converters #1720

cabbonizio opened this issue Apr 20, 2023 · 1 comment · Fixed by #1722 or #1723
Labels
type: enhancement A general enhancement

Comments

@cabbonizio
Copy link

cabbonizio commented Apr 20, 2023

Hi, wanted to ask if this library can support the java.time.YearMonth class as a custom date converters. This object is very useful for storing credit card expiration dates that only require year and month with no other time unit. We have been using all of the out of box converters and this is the only one we have left that requires us to implement our own custom converter and think it would be useful for other users. This is what we have and then override customConversions() in the AbstractCouchbaseConfiguration class. Many thanks for considering it!

@WritingConverter
public enum YearMonthToStringConverter implements Converter<YearMonth, String> {

    INSTANCE;

    @Override
    public String convert(YearMonth source) {
        return Optional.ofNullable(source).map(YearMonth::toString).orElse(null);
    }
}

@ReadingConverter
public enum StringToYearMonthConverter implements Converter<String, YearMonth> {

    INSTANCE;

    @Override
    public YearMonth convert(String source) {
        return Optional.ofNullable(source).map(YearMonth::parse).orElse(null);
    }
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 20, 2023
@mikereiche
Copy link
Collaborator

Hi - did you want to add this to spring-data-couchbase/src/main/java/org/springframework/data/couchbase/core/convert/OtherConverters.java and then add a test case to spring-data-couchbase/src/test/java/org/springframework/data/couchbase/core/mapping/MappingCouchbaseConverterTests.java ?
If you make a PR I'll approve it.

The last line of the commit comment needs to be:

Closes #1720.

  • Mike

@mikereiche mikereiche added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 21, 2023
mikereiche added a commit that referenced this issue Apr 21, 2023
mikereiche added a commit that referenced this issue Apr 21, 2023
mikereiche added a commit that referenced this issue Apr 21, 2023
mikereiche added a commit that referenced this issue Apr 21, 2023
mikereiche added a commit that referenced this issue Apr 21, 2023
mikereiche added a commit that referenced this issue Jun 14, 2023
mikereiche added a commit that referenced this issue Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
3 participants