nevzheng commented on code in PR #13057:
URL: https://github.com/apache/gravitino/pull/13057#discussion_r3997739922
##########
server-common/src/main/java/org/apache/gravitino/server/web/ObjectMapperProvider.java:
##########
@@ -28,38 +29,88 @@
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
+import org.apache.gravitino.dto.responses.ErrorResponse;
@Provider
public class ObjectMapperProvider implements ContextResolver<ObjectMapper> {
+ // Keep diagnostic stacks inside the server and accept legacy payloads while
allowing operators
+ // to omit them from responses.
+ @JsonIgnoreProperties(value = "stack", allowSetters = true)
+ private abstract static class ErrorResponseMixin {}
+
private static class ObjectMapperHolder {
- private static final ObjectMapper INSTANCE =
- JsonMapper.builder()
- .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
- .configure(EnumFeature.WRITE_ENUMS_TO_LOWERCASE, true)
- .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
- .build()
- .setSerializationInclusion(JsonInclude.Include.NON_NULL)
- .registerModule(new JavaTimeModule())
- .registerModule(new Jdk8Module());
+ private static final ObjectMapper WITHOUT_ERROR_STACK_TRACE =
createObjectMapper(false);
+ private static final ObjectMapper WITH_ERROR_STACK_TRACE =
createObjectMapper(true);
+ }
+
+ private final ObjectMapper objectMapper;
+
+ /**
+ * Creates a provider using the backward-compatible server default, which
includes error stack
+ * traces.
+ */
+ public ObjectMapperProvider() {
+ this(JettyServerConfig.INCLUDE_ERROR_STACK_TRACE.getDefaultValue());
+ }
+
+ /**
+ * Creates a provider with explicit error stack-trace serialization behavior.
+ *
+ * @param includeErrorStackTrace whether HTTP error responses should include
diagnostic stack
+ * traces
+ */
+ public ObjectMapperProvider(boolean includeErrorStackTrace) {
+ this.objectMapper = objectMapper(includeErrorStackTrace);
}
/**
- * Retrieves a globally shared {@link ObjectMapper} instance.
+ * Retrieves the shared {@link ObjectMapper} using the backward-compatible
server default.
*
- * <p>Note: This ObjectMapper is a global single instance. If you need to
modify the default
- * serialization/deserialization settings, make changes within the INSTANCE
builder directly.
- * Avoid modifying properties of the returned {@code ObjectMapper} instance
to prevent unintended
- * side effects.
+ * <p>Do not modify the returned mapper. Use {@link #objectMapper(boolean)}
to select explicit
+ * error stack-trace behavior.
*
* @return the globally shared {@link ObjectMapper} instance
*/
public static ObjectMapper objectMapper() {
- return ObjectMapperHolder.INSTANCE;
+ return
objectMapper(JettyServerConfig.INCLUDE_ERROR_STACK_TRACE.getDefaultValue());
Review Comment:
Fixed in
https://github.com/apache/gravitino/pull/13057/commits/9438919c58feeac6109e5335fc91f22570d66dd2.
`ObjectMapperProvider()` and `VersioningFilter()` now delegate to
`ObjectMapperProvider.objectMapper()`, matching `AuthenticationFilter()`, so
the default is resolved in one place.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]