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

feat: add custom json marshaler for sdk.Statement #1936

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dschmidt
Copy link

Proposed Changes

  • add a custom json Marshaler for sdk.Statement that works similar to the Unmarshaler and handles json structured values

If you agree with this change, I'm happy to add tests.

I assume it's a good idea to try to decode the value to make sure it's actual json. I just wasn't sure whether we should return an error if not or if we should just use the value as string.
Opinions?

Checklist

  • I have added or updated unit tests
  • I have added or updated integration tests (if appropriate)
  • I have added or updated documentation

Testing Instructions

@dschmidt dschmidt requested review from a team as code owners February 24, 2025 18:21
Comment on lines +136 to +147
if s.Format == "json-structured" {
raw := json.RawMessage(s.Value)
var tmp interface{}
// Attempt to decode Value to validate it's actual json
if err := json.Unmarshal(raw, &tmp); err == nil {
aux.Value = raw
} else {
aux.Value = s.Value
}
} else {
aux.Value = s.Value
}
Copy link
Member

Choose a reason for hiding this comment

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

I reviewed our implementation of assertions compared to our spec, and it looks like we missed the enum of the statement.format. I've raised this with our architects, and we're going to review the alignment of the ZTDF/BaseTDF spec with the official SDKs (Go, Java, and Web).

I'd suggest implementing the marshaling within your PEP to support this in the short term. Something like:

type MyStatement struct {
  opentdf.Statement
}

func (s *MyStatement) MarshalJSON() ([]byte, error) {
  // ...
}

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively you should be able to just marshal the data since we have the json tags on the Statement.

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.

2 participants