Skip to content

Support for JSR-354 Money & Currency [SPR-12209] #16823

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
spring-projects-issues opened this issue Sep 17, 2014 · 7 comments
Closed

Support for JSR-354 Money & Currency [SPR-12209] #16823

spring-projects-issues opened this issue Sep 17, 2014 · 7 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Sep 17, 2014

Juergen Hoeller opened SPR-12209 and commented

The JSR-354 Money & Currency API looks like a good fit for Spring's binding and formatting features, analogous to Spring 4.0's JSR-310 Date & Time support. JSR-354 comes with a JDK 8 based reference implementation that should be easy enough to support in Spring 4.2 already. The RI is currently in the 1.0 RC stages; it is expected that it'll be at 1.0 GA in time for the Spring Framework 4.2 GA release.


Reference URL: http://javamoney.github.io/

Issue Links:

Referenced from: commits de893ad, 6c169bd

2 votes, 7 watchers

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Introduced MonetaryAmountFormatter and CurrencyUnitFormatter, both registered by default in DefaultFormattingConversionService if the JSR-354 API is present on the classpath. Currently building against the JSR-354 API 1.0-RC3; to be upgraded to 1.0 GA in time for Spring Framework 4.2 RC1.

Any ideas for further JSR-354 support features, let me know. An initial pass only really revealed the need for the above formatters, with no binding-related features having been standardized beyond what we're doing there currently. In particular, there are no pre-defined formatting customizations; it all goes through the MonetaryAmountFormat SPI, with the need to pre-define custom formats under specific format names.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

It turns out that there are ways to make our common @NumberFormat annotation work with MonetaryAmount as well, based on some internal DecimalFormat adapting, so I'm implementing out-of-the-box support for this. Given the lack of fine-grained customization with the JSR-354 MonetaryAmountFormatter mechanism, this seems to be a worthwhile addition.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Initial cut pushed to master now. Some TODOs remain to be revisited, in particular currency detection for @NumberFormat bindings.

@spring-projects-issues
Copy link
Collaborator Author

Elliot Huntington commented

It looks like this ticket is just for formatting. Is there any plan to create a hibernate custom user type to persist a MonetaryAmount?

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Indeed, this ticket is primarily about binding and formatting, plus anything else we could be doing in Spring Framework itself.

Custom user types for Hibernate should rather be submitted to the Hibernate project... FWIW, we don't ship JSR-310 Date-Time adapters for Hibernate, Jackson etc either.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Chris Beams commented

FYI, here's a thread on the BitcoinJ mailing list in which adoption of JSR-354 is being discussed. It'll be nice for bitcoin-related apps to have first-class support in Spring for formatting and binding to these types. https://groups.google.com/d/msg/bitcoinj/vY61tUmZuso/aAnC-HefvU8J

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Finally updated to the recently released JSR-354 API in its 1.0 GA form (adapted to the refactored lookup methods). Remaining parser TODOs addressed as well, with @NumberFormat-based parsing now detecting a currency code at the beginning or end of the given text value if the declared pattern includes the correspondong symbols.

Juergen

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
Development

No branches or pull requests

2 participants