Skip to content

The helpful library to get a better developer experience when combining Money-API with Jakarta and MicroProfile API.

License

Notifications You must be signed in to change notification settings

JavaMoney/jakarta-money

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jakarta-money

Jakarta money is a helpful library for a better developer experience when combining Money-API with Jakarta and MicroProfile API.

The dependency:

<dependency>
   <groupId>org.javamoney</groupId>
   <artifactId>jakarta</artifactId>
   <version>0.0.1-SNAPSHOT</version>
</dependency>

The API brings some libraries that is split by specification:

  • Bean Validator
  • JAXRS
  • CDI
  • JPA
  • JSF
  • XML bind (jaxb)

Bean Validator

JSR 380 is a specification of the Java API for bean validation, part of Jakarta EE and JavaSE. It ensures that the properties of a bean meet specific criteria, using annotations such as @NotNull, @Min, and @Max.

To make an integration with Java-money Jakarta-money has four annotations:

CurrencyAccepted: Informs the currencies that are allowed on validation. It works with MonetaryAmount and CurrencyUnit.

@CurrencyAccepted(currencies = "BRL")
private MonetaryAmount money;
@CurrencyAccepted(currencies = "BRL")
private CurrencyUnit currencyUnit;

CurrencyRejected: Informs the currencies that are rejected on validation. It works with MonetaryAmount and CurrencyUnit.

@CurrencyRejected(currencies = "BRL")
private MonetaryAmount money;
@CurrencyRejected(currencies = "BRL")
private CurrencyUnit currencyUnit;

MonetaryMax: Informs the maximum value of a MonetaryAmount.

@MonetaryMax("10.12")
private MonetaryAmount money;

MonetaryMin: Informs the minimum value of a MonetaryAmount.

@MonetaryMin("10.12")
private MonetaryAmount money;

JAXRS

If you want JAX-RS to automatically convert parameters such as query params, path params, or others, you need to create a ParamConverter.

It has support to:

  • CurrencyUnit
  • MonetaryAmount
@Path("monetary")
@ApplicationScoped
public class MoneyResource {

    @GET
    public String findByCurrency(@QueryParam("currency") CurrencyUnit currency) {
        return "hello, " + currency;
    }
}

JPA

Jakarta Persistence defines a standard for managing persistence and object/relational mapping in Java(R) environments.

It has support to both: MoneyAmount and CurrencyUnit.

@Column
@Convert(converter = CurrencyConverter.class)
private CurrencyUnit currency;

@Column
@Convert(converter = MoneyConverter.class)
private MonetaryAmount money;

CDI

Currency Annotation

The Currency annotation allows to inject a currency unit based in the Currency code.

@Inject
@Currency("USD")
private CurrencyUnit currency;

MonetaryProducer

The MonetaryProducer annotations allows to inject the MonetaryAmountProducer

@Inject
@MonetaryProducer
private MonetaryAmountProducer producer;

@Inject
@Currency("EUR")
private CurrencyUnit currency;

//
MonetaryAmount amount = producer.create(currency, 10);

XML Bind

Jakarta XML Bind provides an XmlAdapter which can be used to transform custom classes to String and vice versa.

@XmlJavaTypeAdapter(CurrencyUnitAdapter.class)
private CurrencyUnit currency;

@XmlJavaTypeAdapter(MonetaryAmountAdapter.class)
private MonetaryAmount money;

About

The helpful library to get a better developer experience when combining Money-API with Jakarta and MicroProfile API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages