Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: evanphx/json-patch
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.8.0
Choose a base ref
...
head repository: evanphx/json-patch
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.8.1
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Jan 16, 2024

  1. Copy the full SHA
    b82b685 View commit details
Showing with 11 additions and 22 deletions.
  1. +2 −22 v5/internal/json/stream.go
  2. +9 −0 v5/patch_test.go
24 changes: 2 additions & 22 deletions v5/internal/json/stream.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ package json

import (
"bytes"
"errors"
"encoding/json"
"io"
)

@@ -259,27 +259,7 @@ func (enc *Encoder) SetEscapeHTML(on bool) {
// RawMessage is a raw encoded JSON value.
// It implements Marshaler and Unmarshaler and can
// be used to delay JSON decoding or precompute a JSON encoding.
type RawMessage []byte

// MarshalJSON returns m as the JSON encoding of m.
func (m RawMessage) MarshalJSON() ([]byte, error) {
if m == nil {
return []byte("null"), nil
}
return m, nil
}

// UnmarshalJSON sets *m to a copy of data.
func (m *RawMessage) UnmarshalJSON(data []byte) error {
if m == nil {
return errors.New("json.RawMessage: UnmarshalJSON on nil pointer")
}
*m = append((*m)[0:0], data...)
return nil
}

var _ Marshaler = (*RawMessage)(nil)
var _ Unmarshaler = (*RawMessage)(nil)
type RawMessage = json.RawMessage

// A Token holds a value of one of these types:
//
9 changes: 9 additions & 0 deletions v5/patch_test.go
Original file line number Diff line number Diff line change
@@ -1236,3 +1236,12 @@ func TestMaintainOrderingIndented(t *testing.T) {
})
}
}

// This is a compile time check that encoding/json's RawMessage can be used in Operation
func init() {
msg := json.RawMessage([]byte(`1`))

_ = Operation{
"foo": &msg,
}
}