Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix json binding with union fields #864

Merged
merged 2 commits into from
Nov 14, 2023
Merged

Fix json binding with union fields #864

merged 2 commits into from
Nov 14, 2023

Conversation

tefra
Copy link
Owner

@tefra tefra commented Nov 14, 2023

📒 Description

xsdata's converter is really designed to work with string values from xml, in case of json with union fields like Union[bool, int, float] the parser will convert by accident float values to int or int values to bool

Resolves #862

🔗 What I've Done

It's not a pretty solution but use the convert to convert everything back to string, we could use the parse_int, parse_float of the json.loads but that would mean we are breaking compatibility with other json libraries.

💬 Comments

A place to write any comments to the reviewer.

🛫 Checklist

Copy link

codecov bot commented Nov 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (075e9da) 99.89% compared to head (f4af825) 99.89%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #864   +/-   ##
=======================================
  Coverage   99.89%   99.89%           
=======================================
  Files         104      104           
  Lines        9295     9298    +3     
  Branches     2078     2078           
=======================================
+ Hits         9285     9288    +3     
  Misses          3        3           
  Partials        7        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@tefra tefra merged commit 2668e1e into main Nov 14, 2023
14 checks passed
@tefra tefra deleted the fix-862 branch November 14, 2023 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loss of Fractional Part in Numbers When Converting Between JSON and Dataclass
1 participant