Skip to content

Query string starts with & when the first property is null #23

Description

@proudust

It seems that if the first property is null, the serialized output starts with &.

#!/usr/bin/env dotnet run
#:package WebSerializer@1.3.0

using System.Runtime.Serialization;
using Cysharp.Web;

var req = new Request(sortBy: null, direction: SortDirection.Desc, currentPage: 3);

var q = WebSerializer.ToQueryString(req);

//await httpClient.GetAsync("/sort?"+ q);
Console.WriteLine("/sort?"+ q);
// expected: /sort?direction=Desc&currentPage=3
// actual: /sort?&direction=Desc&currentPage=3

public record Request(
    [property: DataMember(Order = 0)] string? sortBy,
    SortDirection direction,
    int currentPage
);

public enum SortDirection
{
    Default,
    Asc,
    Desc
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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