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
easyjson currently hardcodes the 'g' format specifier in strconv.AppendFloat() calls for all floating-point serialization. This causes issues for financial applications and other use cases where decimal notation is required instead of scientific notation.
The hardcoded 'g' format can produce scientific notation (e.g., 1.5e-6 instead of 0.000001), which breaks compatibility with systems expecting decimal notation.
Package-level variable for default format that can be overridden via some generated method.
(Needs feasibility check)
Use Cases
Financial applications: Require decimal notation for monetary values
Scientific computing: Need specific precision control
API compatibility: Must match existing JSON parsing expectations
Data interchange: Systems expecting non-scientific notation
This is a common pain point for easyjson users, as evidenced by multiple forks and PRs attempting to address it. A configurable solution would:
Solve the scientific notation issue
Maintain backward compatibility
Provide flexibility for different use cases
Reduce the need for custom forks
I'm willing to contribute the implementation if there's consensus on the approach.
The CLI flag method seems most appropriate as it follows easyjson's existing pattern of configuration options and doesn't break existing code but it hasn't moved ahead and we have been using this. But I am also open to different approaches as well as long as we can fix this.
Problem Statement
easyjson currently hardcodes the 'g' format specifier in strconv.AppendFloat() calls for all floating-point serialization. This causes issues for financial applications and other use cases where decimal notation is required instead of scientific notation.
Current Implementation:
The hardcoded 'g' format can produce scientific notation (e.g., 1.5e-6 instead of 0.000001), which breaks compatibility with systems expecting decimal notation.
Existing Attempts
Proposed Solutions
Option 1: CLI Flag (zerodha fork)
Add -float_format CLI flag that:
Based on the zerodha fork analysis, the changes would be:
Option 2: Struct Tag
Add floatfmt struct tag for field-level control:
(Needs feasibility check)
Option 3: Runtime Configuration
Package-level variable for default format that can be overridden via some generated method.
(Needs feasibility check)
Use Cases
This is a common pain point for easyjson users, as evidenced by multiple forks and PRs attempting to address it. A configurable solution would:
I'm willing to contribute the implementation if there's consensus on the approach.
The CLI flag method seems most appropriate as it follows easyjson's existing pattern of configuration options and doesn't break existing code but it hasn't moved ahead and we have been using this. But I am also open to different approaches as well as long as we can fix this.