Open
Conversation
Contributor
|
@qustavo I'm assuming this is for the webhooks payload alone. Can you give an example of the specific rules in this instance? |
Author
Abolutely, take the following example: package convoy
import (
"encoding/json"
"log"
"testing"
)
type CreateEventRequest struct {
EndpointID string `json:"endpoint_id"`
EventType string `json:"event_type"`
IdempotencyKey string `json:"idempotency_key"`
CustomHeaders map[string]string `json:"custom_headers"`
Data json.RawMessage `json:"data"`
}
type Model struct {
Int int
String string
}
func (m *Model) MarshalJSON() ([]byte, error) {
type Alias Model
return json.MarshalIndent(Alias(*m), "", " ")
}
func TestJSON(t *testing.T) {
data, _ := json.MarshalIndent(&Model{
Int: 42, String: "Hello",
}, "", " ")
ev := CreateEventRequest{
Data: data,
}
bz, _ := json.Marshal(ev)
log.Printf("%s", string(bz))
}Will print Regardless of my |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I have a client that requires the json payload to be formatted following some specific rules.
The following PR allow SDK users to override the default
json.Marshalimplementation and set whatever they need.Note: I tried implementing
MarshalJSONbut it does not work becausejson.Marshalreformats the json payload.