Skip to content

JsonEventFormatter not respecting "WriteIndented" flag #225

@k-krupka

Description

@k-krupka

Hey team,
I'm looking for some advise and/or workaround for my issue. My goal is to create a JSON string (pretty and non-pretty).
As of now, I am using the JsonEventFormatter with the indentation options. The SDK is however not respecting this setting.

The below codebase is showing this problem.

var exampleEvent = new CloudEvent()
{
    Id = "example-id",
    Source = new Uri("http://test.com"),
    Type = "example-type"
};
var formatter = new JsonEventFormatter(new JsonSerializerOptions
{
    WriteIndented = true
}, new JsonDocumentOptions());


byte[] bytes = formatter.EncodeStructuredModeMessage(exampleEvent, out _).ToArray();
var jsonString = Encoding.UTF8.GetString(bytes);

Result:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions