feat(codec): Dual marshal preserve RawJSON#2276
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
f1914e7 to
9afdc77
Compare
9af3528 to
55cd1bf
Compare
anushat05
left a comment
There was a problem hiding this comment.
The build is failing for this should we address that first?
55cd1bf to
4331b71
Compare
9afdc77 to
2f9fa46
Compare
|
@anushat05 The original reason to include the utility is gone with Salesforce using new create method. However, the utility could still come in handy. I think it should replace some of the |
4331b71 to
c1621ec
Compare
|
@anushat05 the PR is still relevant and was useful in the Microsoft Susbcribe implementation. |
df5292b to
d8d8483
Compare
31145b7 to
aacd169
Compare
d8d8483 to
814b593
Compare
814b593 to
f29bab8
Compare
aacd169 to
0d809f3
Compare
|
@jlimatampersand
|
0d809f3 to
006225f
Compare
| // ID string `json:"id"` | ||
| // Name string `json:"name"` | ||
| // } | ||
| type RawJSON[T any] struct { |
There was a problem hiding this comment.
I see what this util is trying to achieve, but is this a necessary util?
I guess the win is there when you edit records in such a way that you are strictly adding items and fields, but if this wrapper is used when removing or deleting for a purpose, this is going to be very buggy and will introduce friction.
You will understand this utility, but many others will easily use it incorrectly unless they actually read this logic fully themselves, which will not be the case. Most likeley 90% of the contributors won't read the description as carefully as the logic itself.
There was a problem hiding this comment.
Convince me or fix the logic so I can approve. I am open to suggestions.
There was a problem hiding this comment.
I understand that it can be misused. Probably it should be more dedicated, or some features stripped away towards more immutable design. I started small, then got some code generated and thought it fits the concept.
(1)
For Microsoft Batch I need Dual Unmarshal -- therefore, it will be part of that Microsoft impl and not a utility:

Usage:

(2)
I changed the code and added tests for DecoratedRecord which has only one responsibility and that won't be growing.
Summary:
- The existing
DecoratedRecordis used by Salesforce. The mock test validates that Salesforce write operation sends correct payload.. - The "DecoratedRecord" is doing only one thing -- enhancing any map with "sidecar data" to produce JSON for payload:
map[string]any+your extension,decoration struct=>JSON
Example:
PS: There are many write payloads that are "decorated", so this idea of DecoratedRecord makes payload construction automatic without any map[string]any assertions, key checks, etc -- it just combines 2 JSON representations. Let me know if it is an overkill 😅 .
eeddc73 to
f3dbeda
Compare
006225f to
f0d71a9
Compare
f0d71a9 to
b5d9039
Compare

Description
This PR introduces
codec.RawJSON[T any].Key changes
codec.RawJSON[T any]A generic wrapper for JSON marshalling/unmarshalling that preserves data in two forms:
map[string]anyTThis enables lossless handling of responses. It’s particularly useful when multiple representations are possible—for example, when parsing provider responses where
Trepresents a success model, but failures require access to the raw payload (e.g. to constructcommon.NewHTTPError).JSON comparison utilities
Adds
mockutils.JSONComparator, a lightweight helper for comparing Go values against JSON string representations (commonly used in tests).Equalscompares single valuesListsEqualcompares slicesThis simplifies assertions where expected data is expressed as JSON literals.
Live Tests