From 882caaed00be8a9ec8a86ef266056e2e30c03fd8 Mon Sep 17 00:00:00 2001 From: Mitsunori Komatsu Date: Thu, 1 Oct 2026 23:16:41 +0900 Subject: [PATCH 1/2] Use MessagePackMapper in the README examples A plain ObjectMapper on MessagePackFactory lacks what MessagePackMapper sets up: a UUID is written as binary that cannot be read back, and a map key that cannot be read back is written instead of refused. The BigDecimal example also mutated the mapper after construction, which Jackson 3 no longer allows; build it with withConfigOverride instead. --- README.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index eeaa259..0a86f96 100644 --- a/README.md +++ b/README.md @@ -49,11 +49,11 @@ dependencies { ### Serialization/Deserialization of POJO -Only thing you need to do is to instantiate `MessagePackFactory` and pass it to the constructor of `tools.jackson.databind.ObjectMapper`. And then, you can use it for MessagePack format data in the same way as jackson-databind. +Only thing you need to do is to instantiate `MessagePackMapper`, a `tools.jackson.databind.ObjectMapper` for MessagePack. And then, you can use it for MessagePack format data in the same way as jackson-databind. ```java // Instantiate ObjectMapper for MessagePack -ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); +ObjectMapper objectMapper = new MessagePackMapper(); // Serialize a Java object to byte array ExamplePojo pojo = new ExamplePojo("komamitsu"); @@ -64,12 +64,6 @@ ExamplePojo deserialized = objectMapper.readValue(bytes, ExamplePojo.class); System.out.println(deserialized.getName()); // => komamitsu ``` -Or more easily: - -```java -ObjectMapper objectMapper = new MessagePackMapper(); -``` - We strongly recommend calling `MessagePackMapper.Builder#handleBigIntegerAndBigDecimalAsString()` if you serialize and/or deserialize BigInteger/BigDecimal values. See [Serialize and deserialize BigDecimal as str type internally in MessagePack format](#serialize-and-deserialize-bigdecimal-as-str-type-internally-in-messagepack-format) for details. ```java @@ -281,9 +275,12 @@ System.out.println(objectMapper.readValue(converted, Pojo.class)); // => Pojo{ `MessagePackMapper.Builder#handleBigIntegerAndBigDecimalAsString()` is equivalent to the following configuration. ```java -ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory()); -objectMapper.configOverride(BigInteger.class).setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING)); -objectMapper.configOverride(BigDecimal.class).setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING)); +ObjectMapper objectMapper = MessagePackMapper.builder() + .withConfigOverride(BigInteger.class, + o -> o.setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING))) + .withConfigOverride(BigDecimal.class, + o -> o.setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING))) + .build(); ``` ### Serialize and deserialize Instant instances as MessagePack extension type @@ -325,7 +322,7 @@ extTypeCustomDesers.addCustomDeser((byte) 59, data -> { return "Not Java"; }); -ObjectMapper objectMapper = new ObjectMapper( +ObjectMapper objectMapper = new MessagePackMapper( new MessagePackFactory().setExtTypeCustomDesers(extTypeCustomDesers)); System.out.println(objectMapper.readValue(bytes, Object.class)); From 5bd072ae87dae65f80e5ccc0a85e76478e27b5e1 Mon Sep 17 00:00:00 2001 From: Mitsunori Komatsu Date: Thu, 1 Oct 2026 23:43:33 +0900 Subject: [PATCH 2/2] Reword the README's basic usage sentence --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a86f96..7a963d9 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ dependencies { ### Serialization/Deserialization of POJO -Only thing you need to do is to instantiate `MessagePackMapper`, a `tools.jackson.databind.ObjectMapper` for MessagePack. And then, you can use it for MessagePack format data in the same way as jackson-databind. +All you need is a `MessagePackMapper`, which is a `tools.jackson.databind.ObjectMapper` for MessagePack. You can then use it for MessagePack data in the same way as jackson-databind. ```java // Instantiate ObjectMapper for MessagePack