Skip to content

Commit 40372f4

Browse files
docs(config): Document ObjectMapper config (#8075)
1 parent 8aea961 commit 40372f4

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

sdk-extensions/incubator/src/main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfiguration.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,31 @@
5353
* <a
5454
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/data-model.md#yaml-file-format">YAML
5555
* configuration file</a>.
56+
*
57+
* <h2>For Implementers</h2>
58+
*
59+
* <p>External consumers needing to parse OpenTelemetry YAML configuration files should use the same
60+
* Jackson ObjectMapper configuration for compatibility. This configuration is intentionally not
61+
* exposed as API to avoid coupling. Instead, copy the following setup:
62+
*
63+
* <pre>{@code
64+
* ObjectMapper mapper = new ObjectMapper()
65+
* // Create empty object instances for keys which are present but have null values
66+
* .setDefaultSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
67+
* // Boxed primitives which are present but have null values should be set to null,
68+
* // rather than empty instances
69+
* mapper.configOverride(String.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SET));
70+
* mapper.configOverride(Integer.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SET));
71+
* mapper.configOverride(Double.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SET));
72+
* mapper.configOverride(Boolean.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SET));
73+
* }</pre>
74+
*
75+
* <p><b>Why this configuration:</b>
76+
*
77+
* <ul>
78+
* <li>Default behavior creates empty objects for null values to match YAML schema expectations
79+
* <li>Boxed primitives remain null to distinguish between absent and explicitly null values
80+
* </ul>
5681
*/
5782
public final class DeclarativeConfiguration {
5883

@@ -62,6 +87,19 @@ public final class DeclarativeConfiguration {
6287
private static final ComponentLoader DEFAULT_COMPONENT_LOADER =
6388
ComponentLoader.forClassLoader(DeclarativeConfigProperties.class.getClassLoader());
6489

90+
/**
91+
* ObjectMapper configured for YAML declarative configuration parsing.
92+
*
93+
* <p>Configuration:
94+
*
95+
* <ul>
96+
* <li>Default: Creates empty objects for present keys with null values
97+
* <li>Boxed primitives (String, Integer, Double, Boolean): Remain null when null
98+
* </ul>
99+
*
100+
* <p>External consumers needing compatible parsing should copy this configuration. See class
101+
* javadoc for details and code example.
102+
*/
65103
// Visible for testing
66104
static final ObjectMapper MAPPER;
67105

0 commit comments

Comments
 (0)