Skip to content

Commit aabe5e2

Browse files
committed
docs: Document public GsonTypeMapper and gsonBuilder()
1 parent ba4adf8 commit aabe5e2

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,32 @@ The library ships an internal `GsonJsonMapper` that is auto-registered for `appl
133133
- For `request.asPojo(MyDto.class)`, delegates to Gson — the target type's fields determine the Java types (`int`, `long`, `Instant`, etc.).
134134
- Round-trips JSR-310 types (`Instant`, `OffsetDateTime`, `ZonedDateTime`, `LocalDateTime`, `LocalDate`, `LocalTime`) as their ISO-8601 string form.
135135

136+
To customize Gson, wire `GsonTypeMapper` explicitly. The no-arg form uses the same JSR-310-aware default as auto-registration; pass a `Gson` to fully control serialization:
137+
138+
```java
139+
var server = OpenApiServer.builder()
140+
.spec(spec)
141+
.jsonMapper(new GsonTypeMapper(myGson))
142+
.handlers(handlers)
143+
.build();
144+
```
145+
146+
To extend the library default (instead of building a `Gson` from scratch), unwrap it via `gsonBuilder()`:
147+
148+
```java
149+
Gson custom =
150+
new GsonTypeMapper()
151+
.gsonBuilder()
152+
.registerTypeAdapter(Money.class, new MoneyAdapter())
153+
.create();
154+
155+
var server = OpenApiServer.builder()
156+
.spec(spec)
157+
.jsonMapper(new GsonTypeMapper(custom))
158+
.handlers(handlers)
159+
.build();
160+
```
161+
136162
For Jackson, the library ships two adapters that wrap an `ObjectMapper` you configure (modules, naming strategy, JSR-310, date formats — all your call). Pick the one that matches your Jackson major:
137163

138164
```java

0 commit comments

Comments
 (0)