From db934e10e3fb23c84ea70e741469e72c46dcb85c Mon Sep 17 00:00:00 2001 From: "Craig P. Motlin" Date: Sat, 4 Jan 2025 19:44:16 -0500 Subject: [PATCH] Propagate the pretty printer from the writer to the generator in `ProviderBase.writeTo()` (#205) --- .../com/fasterxml/jackson/jaxrs/base/ProviderBase.java | 7 ++++++- release-notes/CREDITS-2.x | 6 ++++++ release-notes/VERSION-2.x | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/base/src/main/java/com/fasterxml/jackson/jaxrs/base/ProviderBase.java b/base/src/main/java/com/fasterxml/jackson/jaxrs/base/ProviderBase.java index 9a80ebcd..5fcce21f 100644 --- a/base/src/main/java/com/fasterxml/jackson/jaxrs/base/ProviderBase.java +++ b/base/src/main/java/com/fasterxml/jackson/jaxrs/base/ProviderBase.java @@ -595,7 +595,12 @@ public void writeTo(Object value, Class type, Type genericType, Annotation[] try { // Want indentation? if (writer.isEnabled(SerializationFeature.INDENT_OUTPUT)) { - g.useDefaultPrettyPrinter(); + PrettyPrinter defaultPrettyPrinter = writer.getConfig().getDefaultPrettyPrinter(); + if (defaultPrettyPrinter != null) { + g.setPrettyPrinter(defaultPrettyPrinter); + } else { + g.useDefaultPrettyPrinter(); + } } JavaType rootType = null; diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 448865f6..4db2eb8c 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -106,3 +106,9 @@ Yura (@sdyura) * Contributed #193: `JacksonJaxbJsonProvider` has @Produces(MediaType.WILDCARD) and yet hasMatchingMediaType(MediaType.WILDCARD) return false (2.18.0) + +Craig P. Motlin (@motlin) + +* Contributed #205: Propagate the pretty printer from the writer to the generator in + ProviderBase.writeTo() + (2.19.0) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index cf1e4ed9..fbbd3582 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -14,6 +14,9 @@ Sub-modules: #200: Narrow types to format specific (e.g. CBORMapper) when resolving via JAX-RS Providers +#205: Propagate the pretty printer from the writer to the generator in + ProviderBase.writeTo() + (contributed by @motlin) * Woodstox dependency now 7.1.0 2.18.2 (27-Nov-2024)