You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a JSON body contains a float value like 0.40000000000000002, the log records it as 0.4.
This occurs when the content type is application/json and the request is processed by JacksonJsonFieldBodyFilter.
The original float value is truncated, making the logs inconsistent with the actual request. This can lead to confusion when analyzing logs, as the exact input is not preserved
Expected Behavior
The log should retain and display the original float value exactly as it appeared in the request body, without altering the data.
Actual Behavior
Float values are truncated to 16 significant digits when logged
Possible Fix
The issue stems from how Jackson processes and copies JSON tokens. When Jackson encounters a float value, it parses it as a double, resulting in a loss of precision:
generator.copyCurrentEvent(parser);
Starting from Jackson 2.15+, the following method can be used to handle float values more accurately:
public void copyCurrentEventExact(JsonParser p) throws IOException
This method treats float values as BigDecimal, preserving their full precision.
Note:
• This change may impact performance.
• It is recommended to make this behavior configurable, allowing users to choose between exact precision or standard copying for performance reasons.
Steps to Reproduce
Send a request with a JSON body containing a float value with more than 16 significant digits.
Context
The current behavior results in misleading log entries when float values are involved, potentially affecting debugging and auditing processes
Your Environment
• Framework: Spring WebFlux
• Logging Library: Logbook 3.10.0
• Spring Versions: 3.0.4 / 3.4.0
• Jackson Versions: 2.14, 2.15, 2.18
The text was updated successfully, but these errors were encountered:
When a JSON body contains a float value like 0.40000000000000002, the log records it as 0.4.
This occurs when the content type is application/json and the request is processed by JacksonJsonFieldBodyFilter.
Log output:
The original float value is truncated, making the logs inconsistent with the actual request. This can lead to confusion when analyzing logs, as the exact input is not preserved
Expected Behavior
The log should retain and display the original float value exactly as it appeared in the request body, without altering the data.
Actual Behavior
Float values are truncated to 16 significant digits when logged
Possible Fix
The issue stems from how Jackson processes and copies JSON tokens. When Jackson encounters a float value, it parses it as a double, resulting in a loss of precision:
Starting from Jackson 2.15+, the following method can be used to handle float values more accurately:
This method treats float values as BigDecimal, preserving their full precision.
Note:
• This change may impact performance.
• It is recommended to make this behavior configurable, allowing users to choose between exact precision or standard copying for performance reasons.
Steps to Reproduce
Context
The current behavior results in misleading log entries when float values are involved, potentially affecting debugging and auditing processes
Your Environment
• Framework: Spring WebFlux
• Logging Library: Logbook 3.10.0
• Spring Versions: 3.0.4 / 3.4.0
• Jackson Versions: 2.14, 2.15, 2.18
The text was updated successfully, but these errors were encountered: