Skip to content

Commit

Permalink
Update guide.md
Browse files Browse the repository at this point in the history
Docs for `bosk-jackson`
  • Loading branch information
prdoyle committed Dec 15, 2022
1 parent b5421bd commit 5109003
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ The collection is called `boskCollection` and the document has four fields:
The format of the `state` field is determined by `BsonPlugin`.
The code for `BsonPlugin` will have the details, but some high-level points about the BSON format:

- It does not match the JSON format generated by `bosk-gson`. The two are not mutually compatible. This is a deliberate decision based on differing requirements.
- It does not match the JSON format generated by `bosk-jackson` or `bosk-gson`. This is a deliberate decision based on differing requirements.
- It strongly favours objects over arrays, because object members offer idempotency and (ironically) stronger ordering guarantees.

##### Schema evolution: how to add a new field
Expand Down Expand Up @@ -621,11 +621,27 @@ These rules require that the driver maintains an awareness of the current bosk s
and so most drivers are rarely able to take advantage of these options,
because they can't generally determine what effect an update will have.

### Serialization: `bosk-gson`
### Serialization: `bosk-jackson` and `bosk-gson`

The `bosk-gson` module uses the Gson library to support JSON serialization and deserialization.
The `bosk-jackson` and `bosk-gson` modules use the Jackson and Gson libraries to support JSON serialization and deserialization.

#### Configuring the Gson object
#### Configuring Jackson

To configure an `ObjectMapper` that is compatible with a particular `Bosk` object, use the `JacksonPlugin.moduleFor` method.
Here is an example:

``` java
JacksonPlugin jacksonPlugin = new JacksonPlugin();
boskMapper = new ObjectMapper()
.registerModule(jacksonPlugin.moduleFor(bosk))

// You can add whatever configuration suits your application:
.enable(INDENT_OUTPUT);
```

`JacksonPlugin` is compatible with many of the `ObjectMapper` configuration options, so you should be able to configure it as you want.

#### Configuring Gson

To configure a `Gson` object that is compatible with a particular `Bosk` object, use the `GsonPlugin.adaptersFor` method.
Here is an example:
Expand All @@ -636,14 +652,14 @@ boskGson = new GsonBuilder()
.registerTypeAdapterFactory(gsonPlugin.adaptersFor(bosk))

// You can add whatever configuration suits your application.
// We recommend these.
// We recommend these:
.excludeFieldsWithoutExposeAnnotation()
.setPrettyPrinting()

.create();
```

Note that `GsonPlugin` is compatible with many of the Gson configuration options, so you should be able to configure it as you want.
`GsonPlugin` is compatible with many of the Gson configuration options, so you should be able to configure it as you want.

#### Format

Expand Down

0 comments on commit 5109003

Please sign in to comment.