Skip to content

JsonSerializer throws with trailing whitespace or comments #29472

@watfordgnf

Description

@watfordgnf

Passing JSON with trailing whitespace causes JsonSerializer.Parse to throw (dotnet core 3 preview 5):

{"server_id":"Nf5YR9YRKvA4Od1ofBkOxD","version":"1.0.4","go":"go1.8.3","host":"0.0.0.0","port":4222,"auth_required":false,"ssl_required":false,"tls_required":false,"tls_verify":false,"max_payload":1048576} 

(note single trailing space)

// string json = ... (or ReadOnlySpan)
var info = JsonSerializer.Parse<Info>(json);

// Exception thrown: 'System.Text.Json.JsonReaderException' in System.Text.Json.dll
// "The provided data of length 206 has remaining bytes 1."
//   at System.Text.Json.Serialization.JsonSerializer.ParseCore(String json, Type returnType, JsonSerializerOptions options)
//   at System.Text.Json.Serialization.JsonSerializer.Parse[TValue](String json, JsonSerializerOptions options)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions