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

Add globalns support via SerializerConfig #724

Merged
merged 1 commit into from
Dec 12, 2022
Merged

Conversation

simonschiele
Copy link
Contributor

📒 Description

Write a brief description of your PR.

Add support for a 'globalns' dictionary within SerializerConfig, that gets passed to typing.get_type_hints() on serialization. This will allow to pass a type-resource-mapping like the following, which allows to serialize models without directly importing in the first place:
{ 'City': models.model1.City, 'Street': models.model2.Street, 'House': models.model3.House, }

Resolves #723

🔗 What I've Done

Write a description of the steps taken to resolve the issue

Added support for the dictionary to the SerilizerConfig and passing the value along via the Context to the corresponding calls to typing.get_type_hints().

💬 Comments

A place to write any comments to the reviewer.

🛫 Checklist

@codecov
Copy link

codecov bot commented Nov 28, 2022

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (afd3631) compared to base (351464d).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #724   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          101       101           
  Lines         8780      8784    +4     
  Branches      1951      1951           
=========================================
+ Hits          8780      8784    +4     
Impacted Files Coverage Δ
xsdata/formats/dataclass/context.py 100.00% <100.00%> (ø)
xsdata/formats/dataclass/models/builders.py 100.00% <100.00%> (ø)
xsdata/formats/dataclass/serializers/config.py 100.00% <100.00%> (ø)
xsdata/formats/dataclass/serializers/json.py 100.00% <100.00%> (ø)
xsdata/formats/dataclass/serializers/xml.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@tefra
Copy link
Owner

tefra commented Dec 4, 2022

Looks good @simonschiele , can you please add a practical example in the docs https://github.com/tefra/xsdata/tree/master/docs/examples

@tefra
Copy link
Owner

tefra commented Dec 4, 2022

The fix for the pre-commit hook is on master

@simonschiele
Copy link
Contributor Author

Thanks, writing a small doc with a usage scenario atm and will rebase for the pre-commit.

@sonarqubecloud
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
No Duplication information No Duplication information

@tefra tefra merged commit 751198b into tefra:master Dec 12, 2022
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.

Add globalns paramater for get_type_hints to SerializerConfig
2 participants