Skip to content

Commit

Permalink
Merge pull request #651 from msgpack/doc-jackson-bigdecimal-str
Browse files Browse the repository at this point in the history
Add how to internally represent BigDecimal as str to the doc
  • Loading branch information
komamitsu committed Jun 13, 2022
2 parents ec9b958 + 4c5d180 commit 4f6579f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions msgpack-jackson/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,22 @@ When you want to use non-String value as a key of Map, use `MessagePackKeySerial
System.out.println(deserialized); // => {42=Hello}
```

### Serialize and deserialize BigDecimal as str type internally in MessagePack format

`jackson-dataformat-msgpack` represents BigDecimal values as float type in MessagePack format by default. When you want to handle BigDeciaml values as str type with arbitrary precision in MessagePack format, you can use `com.fasterxml.jackson.databind.cfg.MutableConfigOverride#setFormat` like this:

```java
ObjectMapper mapper = new ObjectMapper(new MessagePackFactory());
mapper.configOverride(BigDecimal.class).setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING));

Pojo obj = new Pojo();
obj.value = new BigDecimal("1234567890.98765432100");

byte[] converted = mapper.writeValueAsBytes(obj);

System.out.println(mapper.readValue(converted, Pojo.class)); // => Pojo{value=1234567890.98765432100}
```

### Deserialize extension types with ExtensionTypeCustomDeserializers

`ExtensionTypeCustomDeserializers` helps you to deserialize extension types easily.
Expand Down

0 comments on commit 4f6579f

Please sign in to comment.