[Bug]: json-xml-mediator policy writes large and small JSON numbers in exponent form

Open Beginner friendly
#4,465 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
api, backend

Research direction

Start by locating the json-xml-mediator policy code that formats JSON numbers with Go's %g verb; the issue identifies the policy and the affected behavior but no file or test. Check how existing policy tests cover JSON-to-XML conversion, then add cases for 1234567 and 0.00001. Done means those XML elements preserve the decimal values instead of using exponent notation, with the relevant tests passing.

Written by the indexing model from the issue text.

Description

Area/Policies Aspect/API Severity/Major Type/Bug
Please select the area the issue is related to

Gateway

Please select the aspect the issue is related to

Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI)

Description

The json-xml-mediator policy converts a JSON request to XML for the backend. It formats every JSON number with Go's %g verb.

%g switches to exponent form for numbers of a million or more and for numbers below 0.0001. So 1234567 reaches the backend as 1.234567e+06, and 0.00001 as 1e-05. An XML backend that expects decimal digits rejects or misreads these values.

Numbers between 0.0001 and a million are not affected. The policy doc says the policy converts all JSON data types.

Expected Behaviour

The XML element holds the number as the JSON wrote it, such as 1234567 and 0.00001.

Actual Behaviour

The backend receives <root><population>1.234567e+06</population><ratio>1e-05</ratio></root>.

Steps to Reproduce
  1. Create a REST API with the policy on a POST operation:
    {"name":"json-xml-mediator","version":"v1","params":{"downsteamPayloadFormat":"json","upstreamPayloadFormat":"xml"}}
    
  2. Send {"population":12345,"ratio":0.5} with Content-Type: application/json. The backend receives <root><population>12345</population><ratio>0.5</ratio></root>.
  3. Send {"population":1234567,"ratio":0.00001}. The backend receives <root><population>1.234567e+06</population><ratio>1e-05</ratio></root>.
Severity Level of the Issue

Severity/Major (Important functionality is broken. Should be prioritized. Doesn't need immediate attention)

Environment Details (with versions)
  • Gateway versions: 1.1.0, 1.2.0 and latest
  • Policy: json-xml-mediator v1.1.0, wso2/gateway-controllers main 5b8e3367
  • Upstream: a test service that records the request body
Dominant language
Go
Stars
85
Forks
142
Avg merge
1d 6h
Merged PRs (30d)
250

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from wso2/api-platform

All issues in wso2/api-platform

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.