16 Juni 2020

Money & Currency API

Download .zip Download .tar.gz View on GitHub

What is JSR 354?

JSR 354 provides a portable and extendible framework for handling of Money & Currency. The API models monetary amounts and currencies in a platform independent and portable way, including well defined extension points. It's API defines a simple yet flexible contract that enables users to choose the implementation matching their target requirements best and having full control about the numeric state at all stages during monetary processing.
The JSR is lead by Trivadis AG (trivadis.com), Werner Keil (@keilw) and Otavio Santana (@otaviojava)
You can access the API by adding the following Maven dependencies:

<dependency>
  <groupId>javax.money</groupId>
  <artifactId>money-api</artifactId>
  <version>1.1</version>
</dependency>

Further versions can be found here.

The release artifacts should be accessible from the following repositories:

  • Maven Central

Though it is possible to compile your programs completely with the API, in most cases, you will also have to add an implementation, e.g. the Moneta reference implementation.

Overview

The API basically consists of four packages:

  • javax.money contains the main artifacts of the API, e.g. the interfaces for MonetaryAmount, CurrencyUnit, MonetaryOperator, MonetaryQuery, and the accessor singletons for amounts, currencies and roundings.
  • javax.money.convert contains currency conversion logic.
  • javax.money.format contains the formatting logic, which has some similarities with java.text but relies more on immutable artifacts and builders.
  • javax.money.spi contains the service provider interfaces and the bootstrap logic, which allows to configure the API also within EE contexts (e.g. running it within a CDI container).
The Java 9 "Jigsaw" module is java.money.

Documentation

Since it a Java Specification Request check out out JSR's specification from the JSR 354 Detail Page.