Skip to content

JSON Marshal error on generated empty OptString struct #660

Open
@exu

Description

@exu

What version of ogen are you using?

v0.54.1

Can this issue be reproduced with the latest version?

Yes just try to run this test in directory where API is generated with OptString

package api

import (
	"testing"

	"encoding/json"
)

func TestOpString(t *testing.T) {

	s := OptString{}

	_, err := json.Marshal(s)

	if err != nil {
		t.Fatalf("error should be nil, got %v", err)
	}

}

So for most use cases with fields set to not required when trying to marshal it (e.g. send through event bus) it's not possible to use ogen.

Getting output:

--- FAIL: TestOpString (0.00s)
    /Users/exu/code/kube/testkube-cloud-api/pkg/api/optstring_test.go:16: 
   error should be nil, got json: error calling MarshalJSON for type api.OptString: 
   unexpected end of JSON input

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions