easyjson noexponent

Upstream contribution to mailru/easyjson adding a noexponent struct tag for controlling float serialization format.

Problem

Financial applications need decimal notation (0.000001) instead of scientific notation (1e-6). The default Go JSON encoder uses scientific notation for small floats, which breaks downstream consumers expecting decimal format.

Solution

Added noexponent struct tag following the existing asString pattern:

type Price struct {
    Value   float64 `json:"value,noexponent"`        // โ†’ 100000000
    Regular float64 `json:"regular"`                  // โ†’ 1e8
}

Implementation

  • 4 new Writer methods: Float32NoExp, Float64NoExp, Float32StrNoExp, Float64StrNoExp
  • Tag parsing in gen/encoder.go
  • Comprehensive test coverage
  • ~80 lines of code

Status

Inspired by noexponent tag pattern in google/go-querystring.