Open ziemekobel-ef opened 1 year ago
It's probably related to the map hiter header copied from the runtime, used to reduce allocations for map ranges. I'll have a look.
Can you tell me which version of Go you are using please, and share the unit test you seems to be using ?
@wI2L It's 1.21
And here's the entire test code:
package lib_test
import (
"encoding/json"
"fmt"
"testing"
"github.com/wI2L/jettison"
)
type Fields struct {
AdditionalProperties map[string]string `json:"-"`
}
func (a Fields) MarshalJSON() ([]byte, error) {
var err error
object := make(map[string]json.RawMessage)
for fieldName, field := range a.AdditionalProperties {
object[fieldName], err = json.Marshal(field)
if err != nil {
return nil, fmt.Errorf("error marshaling '%s': %w", fieldName, err)
}
}
return json.Marshal(object)
}
func TestJettison(t *testing.T) {
v := Fields{
AdditionalProperties: map[string]string{
"foo": "bar",
},
}
_, err := jettison.Marshal(v)
if err != nil {
t.Fatal(err)
}
}
@ziemekobel-ef Found the issue, I'll send a fix for it.
yes, same error here.
import "gorm.io/datatypes"
struct A {
B datatypes.JSONMap // type JSONMap map[string]interface{}
}
datatypes.JSONMap is a map[string]
type, which cause out of memory error.
Marshalling panics when a struct containing a map field and a custom MarshalJSON() is provided. Tested on Apple M1 Pro, running macOS 14.0.
The below test code:
results in: