Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());
ObjectMapper objectMapper = new MessagePackMapper();

// Serialize a Java object to byte array
ExamplePojo pojo = new ExamplePojo("komamitsu");
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
Loading