FasterXML / FasterXML/jackson-databind

Provide an ObjectMapper configuration (`DeserializationFeature`) to automatically do `clearLocation()` for `JacksonException`

Open
#3,340 5 comments 3 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
3.7k
Forks
1.5k
Avg merge
3d 6h
Merged PRs (30d)
28

Description

**Is your feature request related to a problem? Please describe.**

You can manually call `JsonProcessingException.clearLocation()` to clear location data, so that sensitive data in a invalid json won't be in error message when logged.

But there are still problems:
* I should try/catch `JsonProcessingException` and call `clearLocation()` everywhere I need parsing. This is troublesome.
* Some frameworks like Spring calls ObjectMapper deep inside its library and I can't do a try/catch there, e.g. RESTFul request JSON parsing.

So I hope this can be automatically done.

There is a AOP-based solution [here](https://stackoverflow.com/a/68815934) . But I think it's too hacky.

**Describe the solution you'd like**

I hope there can be an `ObjectMapper` config like
`
ObjectMapper objectMapper = new ObjectMapper().disable(MapperFeature.LOCATION_IN_PROCESSING_EXCEPTION);
`
, so that JsonProcessionException (and its subclasses) 's location will always be null.

In Spring, I can make this objectMapper as a singleton bean and Spring's library will use it.

**Usage example**
See above

**Additional context**
N/A

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.