Skip to content

bladnor/jackson-datatype-money

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jackson Datatype Money

Jackson module (jar) to support JSON serialization and deserialization of javax.money data types.

Build Status Coverage Status Release Maven Central

Dependency

<dependency>
    <groupId>org.zalando</groupId>
    <artifactId>jackson-datatype-money</artifactId>
    <version>${jackson-datatype-money.version}</version>
</dependency>

This module has no direct dependency on Java Money, but rather requires that clients pick one in their project directly. This allows this module to be compatible with the official version as well as the backport of Java Money. Pick one of the following dependency sets:

Java 7

<dependency>
    <groupId>javax.money</groupId>
    <artifactId>money-api-bp</artifactId>
    <version>${java-money.version}</version>
</dependency>
<dependency>
    <groupId>org.javamoney</groupId>
    <artifactId>moneta-bp</artifactId>
    <version>${java-money.version}</version>
</dependency>

Java 8

<dependency>
    <groupId>javax.money</groupId>
    <artifactId>money-api</artifactId>
    <version>${java-money.version}</version>
</dependency>
<dependency>
    <groupId>org.javamoney</groupId>
    <artifactId>moneta</artifactId>
    <version>${java-money.version}</version>
</dependency>

Usage

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new MoneyModule());

Or alternatively you can use the SPI capabilities:

ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();

Supported Types

The module supports de/serialization of the following types:

Currency.getInstance("EUR") produces an ISO-4217 currency code, e.g. "EUR".

Monetary.getCurrency("EUR") produces an ISO-4217 currency code, e.g. "EUR".

Money.of(29.95, "EUR") produces the following structure:

{
  "amount": 29.95, 
  "currency": "EUR"
}

License

Copyright [2015] Zalando SE

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Extension module to properly support datatypes of javax.money.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 98.6%
  • Shell 1.4%