Dropwizard Money Bundle
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.mvn/wrapper
src
.editorconfig
.gitignore
.travis.yml
.travis_after_success.sh
LICENSE
README.md
maven_deploy_settings.xml
mvnw
mvnw.cmd
pom.xml
spotbugs.xml

README.md

Dropwizard Money

Build Status Coverage Status Maven Central GitHub license Become a Patron

A bundle for using Money objects in Dropwizard applications. This bundle provides:

  • Jackson module for serializing/deserializing Money/FastMoney objects
  • JDBI argument mappers for persisting Money objects as a BigDecimal SQL type
  • JDBI argument mappers for persisting FastMoney objects as a Numeric SQL type
  • Jersey MoneyParam for serializing/deserialzing Money objects
  • Jersey FastMoneyParam for serializing/deserialzing FastMoney objects
  • Jersey MonetaryExceptionMapper for handling MonetaryException

Usage

Within your Configuration class, add the following:

@Valid
@NotNull
private final MoneyFactory money = new MoneyFactory();

@JsonProperty
public MoneyFactory getMoneyFactory() {
    return money;
}

Then within your Application class:

@Override
public void initialize(Bootstrap<MyConfiguration> bootstrap) {
    bootstrap.addBundle(new MoneyBundle<MyConfiguration>() {
        @Override
        public MoneyFactory getMoneyFactory(MyConfiguration configuration) {
            return configuration.getMoneyFactory();
        }
    });
}

@Override
public void run(MyConfiguration config, Environment environment) throws Exception {
    final String defaultCurrency = config.getMoneyFactory().getDefaultCurrencyCode();

    final DBIFactory factory = new DBIFactory();
    final DBI jdbi = factory.build(environment, config.getDataSourceFactory(), "postgresql");
    jdbi.registerArgumentFactory(new MoneyArgumentFactory());
    jdbi.registerColumnMapper(new MoneyMapper(defaultCurrency));
}

Maven Artifacts

This project is available on Maven Central. To add it to your project simply add the following dependencies to your pom.xml:

<dependency>
    <groupId>com.smoketurner.dropwizard</groupId>
    <artifactId>dropwizard-money</artifactId>
    <version>1.2.0-1</version>
</dependency>

Support

Please file bug reports and feature requests in GitHub issues.

License

Copyright (c) 2018 Smoke Turner, LLC

This library is licensed under the Apache License, Version 2.0.

See http://www.apache.org/licenses/LICENSE-2.0.html or the LICENSE file in this repository for the full license text.