Skip to content

Commit

Permalink
Performance improvents to LiteralSerializer (#265)
Browse files Browse the repository at this point in the history
- No longer boxes when serializing some value types such as int, long, and Guid
- Don't unnecessarily load CultureInfo.InvariantCulture for Guid
- Use "." separator for PathSegmentStyle.Label regardless of the value of "explode" (this correctly follows the specification)

**Breaking changes
- LiteralSerializer and HeaderSerializer are now static classes
  • Loading branch information
brantburnett authored Oct 20, 2024
1 parent a000c31 commit cb04589
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void SerializePrimitive_String_ReturnsString()
{
// Act

string result = HeaderSerializer.Instance.SerializePrimitive("test");
string result = HeaderSerializer.SerializePrimitive("test");

// Assert

Expand All @@ -27,7 +27,7 @@ public void SerializePrimitive_Integer_ReturnsString()
{
// Act

string result = HeaderSerializer.Instance.SerializePrimitive(105);
string result = HeaderSerializer.SerializePrimitive(105);

// Assert

Expand All @@ -39,7 +39,7 @@ public void SerializePrimitive_Long_ReturnsString()
{
// Act

string result = HeaderSerializer.Instance.SerializePrimitive(105L);
string result = HeaderSerializer.SerializePrimitive(105L);

// Assert

Expand All @@ -51,7 +51,7 @@ public void SerializePrimitive_Float_ReturnsString()
{
// Act

string result = HeaderSerializer.Instance.SerializePrimitive(1.05f);
string result = HeaderSerializer.SerializePrimitive(1.05f);

// Assert

Expand All @@ -63,7 +63,7 @@ public void SerializePrimitive_Double_ReturnsString()
{
// Act

string result = HeaderSerializer.Instance.SerializePrimitive(1.05);
string result = HeaderSerializer.SerializePrimitive(1.05);

// Assert

Expand All @@ -75,7 +75,7 @@ public void SerializePrimitive_True_ReturnsString()
{
// Act

string result = HeaderSerializer.Instance.SerializePrimitive(true);
string result = HeaderSerializer.SerializePrimitive(true);

// Assert

Expand All @@ -87,7 +87,7 @@ public void SerializePrimitive_False_ReturnsString()
{
// Act

string result = HeaderSerializer.Instance.SerializePrimitive(false);
string result = HeaderSerializer.SerializePrimitive(false);

// Assert

Expand All @@ -99,7 +99,7 @@ public void SerializePrimitive_DateTime_ReturnsString()
{
// Act

string result = HeaderSerializer.Instance.SerializePrimitive(new DateTime(2020, 1, 2, 3, 4, 5));
string result = HeaderSerializer.SerializePrimitive(new DateTime(2020, 1, 2, 3, 4, 5));

// Assert

Expand All @@ -111,7 +111,7 @@ public void SerializePrimitive_Date_ReturnsString()
{
// Act

string result = HeaderSerializer.Instance.SerializePrimitive(new DateTime(2020, 1, 2, 3, 4, 5), "date");
string result = HeaderSerializer.SerializePrimitive(new DateTime(2020, 1, 2, 3, 4, 5), "date");

// Assert

Expand All @@ -127,7 +127,7 @@ public void SerializeList_List_ReturnsCommaDelimitedString()
{
// Act

string result = HeaderSerializer.Instance.SerializeList(
string result = HeaderSerializer.SerializeList(
new List<string> { "abc", "def", "ghi" });

// Assert
Expand All @@ -140,7 +140,7 @@ public void SerializeList_DateList_ReturnsCommaDelimitedString()
{
// Act

string result = HeaderSerializer.Instance.SerializeList(
string result = HeaderSerializer.SerializeList(
new List<DateTime> {
new(2020, 01, 02, 3, 4, 5),
new(2021, 01, 02, 3, 4, 5)
Expand All @@ -160,7 +160,7 @@ public void DeserializePrimitive_String_ReturnsString()
{
// Act

string result = HeaderSerializer.Instance.DeserializePrimitive<string>(
string result = HeaderSerializer.DeserializePrimitive<string>(
["test"]);

// Assert
Expand All @@ -173,7 +173,7 @@ public void DeserializePrimitive_MultipleStrings_ReturnsJoined()
{
// Act

string result = HeaderSerializer.Instance.DeserializePrimitive<string>(
string result = HeaderSerializer.DeserializePrimitive<string>(
["test", "value"]);

// Assert
Expand All @@ -186,7 +186,7 @@ public void DeserializePrimitive_Integer_ReturnsString()
{
// Act

int result = HeaderSerializer.Instance.DeserializePrimitive<int>(
int result = HeaderSerializer.DeserializePrimitive<int>(
["105"]);

// Assert
Expand All @@ -199,7 +199,7 @@ public void DeserializePrimitive_Long_ReturnsString()
{
// Act

long result = HeaderSerializer.Instance.DeserializePrimitive<long>(
long result = HeaderSerializer.DeserializePrimitive<long>(
["105"]);

// Assert
Expand All @@ -212,7 +212,7 @@ public void DeserializePrimitive_Float_ReturnsString()
{
// Act

float result = HeaderSerializer.Instance.DeserializePrimitive<float>(
float result = HeaderSerializer.DeserializePrimitive<float>(
["1.05"]);

// Assert
Expand All @@ -225,7 +225,7 @@ public void DeserializePrimitive_Double_ReturnsString()
{
// Act

double result = HeaderSerializer.Instance.DeserializePrimitive<double>(
double result = HeaderSerializer.DeserializePrimitive<double>(
["1.05"]);

// Assert
Expand All @@ -238,7 +238,7 @@ public void DeserializePrimitive_True_ReturnsString()
{
// Act

bool result = HeaderSerializer.Instance.DeserializePrimitive<bool>(
bool result = HeaderSerializer.DeserializePrimitive<bool>(
["true"]);

// Assert
Expand All @@ -251,7 +251,7 @@ public void DeserializePrimitive_False_ReturnsString()
{
// Act

bool result = HeaderSerializer.Instance.DeserializePrimitive<bool>(
bool result = HeaderSerializer.DeserializePrimitive<bool>(
["false"]);

// Assert
Expand All @@ -264,7 +264,7 @@ public void DeserializePrimitive_Date_ReturnsString()
{
// Act

var result = HeaderSerializer.Instance.DeserializePrimitive<DateTime>(
var result = HeaderSerializer.DeserializePrimitive<DateTime>(
["2020-01-02"], "date");

// Assert
Expand All @@ -277,7 +277,7 @@ public void DeserializePrimitive_DateWithUnexpectedTime_FormatException()
{
// Act/Assert

var action = () => HeaderSerializer.Instance.DeserializePrimitive<DateTime>(
var action = () => HeaderSerializer.DeserializePrimitive<DateTime>(
["2020-01-02T03:04:05-04:00"], "date");
action.Should().Throw<FormatException>();
}
Expand All @@ -289,7 +289,7 @@ public void DeserializePrimitive_DateTimeOffset_ReturnsString(string format)
{
// Act

var result = HeaderSerializer.Instance.DeserializePrimitive<DateTimeOffset>(
var result = HeaderSerializer.DeserializePrimitive<DateTimeOffset>(
["2020-01-02T03:04:05-04:00"], format);

// Assert
Expand All @@ -306,7 +306,7 @@ public void DeserializeList_ListOfStrings_ReturnsStrings()
{
// Act

List<string> result = HeaderSerializer.Instance.DeserializeList<string>(
List<string> result = HeaderSerializer.DeserializeList<string>(
["abc", "def", "ghi"]);

// Assert
Expand All @@ -319,7 +319,7 @@ public void DeserializeList_ListOfIntegers_ReturnsIntegers()
{
// Act

List<int> result = HeaderSerializer.Instance.DeserializeList<int>(
List<int> result = HeaderSerializer.DeserializeList<int>(
["1", "3", "5"]);

// Assert
Expand Down
Loading

0 comments on commit cb04589

Please sign in to comment.