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

types: clean up JSON unmarshaling story for extension types #64

Merged
merged 7 commits into from
Nov 12, 2024

Conversation

patjakdev
Copy link
Collaborator

@patjakdev patjakdev commented Nov 12, 2024

Issue #, if available: None

Description of changes:

Create a generic unmarshalExtensionValue() helper function that supports all three forms of extension value JSON encoding:

  • Explicit: { "__extn": { "fn": "decimal", "arg": "1234.5678" } }
  • Implicit object: { "fn": "decimal", "arg": "1234.5678" } }
  • Implicit string: "1234.5678"

Use it to flesh out the implementations of UnmarshalJSON for IPAddr and Decimal. Note that the implicit decoding will never actually be invoked until we have schema-driven decoding for entities.

@patjakdev patjakdev marked this pull request as ready for review November 12, 2024 20:52
@patjakdev patjakdev requested review from apg and philhassey November 12, 2024 20:52
Comment on lines +131 to +132
var zeroT T
var arg string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could combine this into one var declaration

Suggested change
var zeroT T
var arg string
var (
zeroT T
arg string
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer the two line version...

types/json.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@philhassey philhassey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@patjakdev patjakdev force-pushed the json-encoding-cleanup branch from a1f1f5f to 3b282ac Compare November 12, 2024 23:38
@patjakdev patjakdev merged commit c7cc1e3 into cedar-policy:main Nov 12, 2024
3 checks passed
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.

3 participants