Cysharp / Cysharp/WebSerializer
Query string starts with `&` when the first property is null
Open
Beginner friendly
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 79
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
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¤tPage=3
// actual: /sort?&direction=Desc¤tPage=3
public record Request(
[property: DataMember(Order = 0)] string? sortBy,
SortDirection direction,
int currentPage
);
public enum SortDirection
{
Default,
Asc,
Desc
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the WebSerializer.ToQueryString entry point and reproduce the provided Request example, where the first property is null. Add a regression test for the expected query string without a leading ampersand, then verify the existing serialization tests still pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100