Skip to content

feat(codec): JSON Record decorator#2248

Merged
Cobalt0s merged 3 commits into
mainfrom
cobalt0s/record-decorator
Nov 5, 2025
Merged

feat(codec): JSON Record decorator#2248
Cobalt0s merged 3 commits into
mainfrom
cobalt0s/record-decorator

Conversation

@Cobalt0s
Copy link
Copy Markdown
Contributor

@Cobalt0s Cobalt0s commented Oct 31, 2025

Description

This utility simplifies constructing payloads from records in Go, especially for Salesforce API integration.

In Go, anonymous struct embedding works perfectly for structs: embedded fields are injected at the same level, so you can compose a final JSON body from multiple structs and every field is "inherited" naturally on the same JSON node level.

However, this approach doesn’t work for non-struct properties. common.Record is a map[string]any, so a special decorator is required to merge additional properties.

For Salesforce, the difference between the client-supplied record and the payload is that we must:

  1. Add the type of record (Salesforce object name).
  2. Create a unique reference ID for bookkeeping, which is enforced by the API.

This utility makes it easy to create a Salesforce-ready model (NOTE: there is some existing code in some connector that also does side-car property emebeding which would benefit from it). During JSON marshaling, properties from Extension are automatically merged into Record.
image

Input:

[
  {
    "FirstName": "Siena",
    "LastName": "Dyer"
  },
  {
    "FirstName": "Markus",
    "LastName": "Blevins"
  }
]

Output:

{
  "records": [
    {
      "FirstName": "Siena",
      "LastName": "Dyer",
      "attributes": {
        "referenceId": "ref0",
        "type": "Contact"
      }
    },
    {
      "FirstName": "Markus",
      "LastName": "Blevins",
      "attributes": {
        "referenceId": "ref1",
        "type": "Contact"
      }
    }
  ]
}

Copy link
Copy Markdown
Contributor Author

Cobalt0s commented Oct 31, 2025

@Cobalt0s Cobalt0s self-assigned this Oct 31, 2025
@Cobalt0s Cobalt0s requested a review from laurenzlong October 31, 2025 03:18
@Cobalt0s Cobalt0s marked this pull request as ready for review October 31, 2025 03:18
@Cobalt0s Cobalt0s force-pushed the cobalt0s/client-custom-err-conditional branch from 2d13aed to 8a46341 Compare November 3, 2025 21:57
@Cobalt0s Cobalt0s force-pushed the cobalt0s/record-decorator branch from 94c3e21 to 483ce73 Compare November 3, 2025 21:57
@Cobalt0s Cobalt0s force-pushed the cobalt0s/record-decorator branch from 483ce73 to fbedc4a Compare November 4, 2025 17:33
@Cobalt0s Cobalt0s force-pushed the cobalt0s/client-custom-err-conditional branch from 8a46341 to 1863886 Compare November 4, 2025 17:33
@Cobalt0s Cobalt0s force-pushed the cobalt0s/record-decorator branch from fbedc4a to deb0891 Compare November 4, 2025 20:36
@Cobalt0s Cobalt0s force-pushed the cobalt0s/client-custom-err-conditional branch from 1863886 to 420d747 Compare November 4, 2025 20:36
@Cobalt0s Cobalt0s requested a review from anushat05 November 4, 2025 22:54
@Cobalt0s Cobalt0s force-pushed the cobalt0s/record-decorator branch from deb0891 to a2ad746 Compare November 5, 2025 00:51
@Cobalt0s Cobalt0s force-pushed the cobalt0s/client-custom-err-conditional branch from 420d747 to aec7c2b Compare November 5, 2025 00:51
Base automatically changed from cobalt0s/client-custom-err-conditional to main November 5, 2025 00:55
@Cobalt0s Cobalt0s merged commit e40ccf1 into main Nov 5, 2025
9 checks passed
@Cobalt0s Cobalt0s deleted the cobalt0s/record-decorator branch November 5, 2025 00:57
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