Jackson module (jar) to support JSON serialization and deserialization of javax.money data types.
<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:
<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>
<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>
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new MoneyModule());
Or alternatively you can use the SPI capabilities:
ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
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"
}
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.