Skip to content

Provides methods for serializing & deserializing objects as URL-encoded query strings.

License

Notifications You must be signed in to change notification settings

erinnmclaughlin/Tizzani.QueryStringSerializer

Repository files navigation


Query String Serializer

Lightweight serializer for query strings and .NET objects.

Nuget version Nuget downloads GitHub last commit GitHub Workflow Status (with event)

Installation

Download from NuGet.

dotnet add package Tizzani.QueryStringSerializer --version 8.0.0

Example Usage

Serialization

var order = new Order
{
    Customer = new Customer { Name = "Jack Sparrow" },
    Items = new List<OrderItem>
    {
        new OrderItem { Description = "Rum", Quantity = 5 },
        new OrderItem { Description = "Jar of Dirt", Quantity = 1 }
    }
};

var queryString = QueryStringSerializer.Serialize(order);
// "Customer.Name=Jack+Sparrow&Items.Description=Rum&Items.Quantity=5&Items.Description=Jar+of+Dirt&Items.Quantity=1";

Deserialization

var queryString = "Customer.Name=Jack+Sparrow&Items.Description=Rum&Items.Quantity=5&Items.Description=Jar+of+Dirt&Items.Quantity=1";
var order = QueryStringSerializer.Deserialize<Order>(queryString);

Configuration

To configure how query strings are serialized, use QueryStringSerializerOptions.

enum Status { Placed, Canceled, Completed }
var order = new Order { Status = Status.Canceled };
var qs1 = QueryStringSerializer.Serialize(order); // "Status=Canceled"
var qs2 = QueryStringSerializer.Serialize(order, new() { EnumsAsStrings = false }); // "Status=1"

About

Provides methods for serializing & deserializing objects as URL-encoded query strings.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages