Skip to content

Commit

Permalink
Use invariant culture for (de)serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinM85 committed Jul 18, 2024
1 parent 9ccd477 commit cf1c752
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/serialization/json/Converters/JsonDateConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public override void Write(Utf8JsonWriter writer, Date value, JsonSerializerOpti
=> WriteInternal(writer, value);

private static Date ReadInternal(ref Utf8JsonReader reader)
=> new Date(DateTime.ParseExact(reader.GetString()!, "dd---MM---yyyy", CultureInfo.InvariantCulture));
=> new Date(DateTime.ParseExact(reader.GetString(), "dd---MM---yyyy", CultureInfo.InvariantCulture));

private static void WriteInternal(Utf8JsonWriter writer, Date value)
=> writer.WriteStringValue($"{value.Day}---{value.Month}---{value.Year}");
=> writer.WriteStringValue(value.ToString());
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Microsoft.Kiota.Serialization.Json.Tests.Converters;
/// </summary>
public class JsonDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
{
private const string Format = "dd__MM__yyyyTHH_mm_ssZ";
/// <inheritdoc />
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
=> reader.TokenType == JsonTokenType.Null
Expand All @@ -21,8 +22,8 @@ public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSeri
=> WriteInternal(writer, value);

private static DateTimeOffset ReadInternal(ref Utf8JsonReader reader)
=> DateTimeOffset.ParseExact(reader.GetString()!, "dd__MM__yyyyTHH_mm_ssZ", CultureInfo.InvariantCulture);
=> DateTimeOffset.ParseExact(reader.GetString(), Format, CultureInfo.InvariantCulture);

private static void WriteInternal(Utf8JsonWriter writer, DateTimeOffset value)
=> writer.WriteStringValue(value.ToString("dd__MM__yyyyTHH_mm_ssZ"));
=> writer.WriteStringValue(value.ToString(Format));
}
4 changes: 2 additions & 2 deletions tests/serialization/json/Converters/JsonTimeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public override void Write(Utf8JsonWriter writer, Time value, JsonSerializerOpti
=> WriteInternal(writer, value);

private static Time ReadInternal(ref Utf8JsonReader reader)
=> new Time(DateTime.ParseExact(reader.GetString()!, "HH__mm__ss", CultureInfo.InvariantCulture));
=> new Time(DateTime.ParseExact(reader.GetString(), "HH__mm__ss", CultureInfo.InvariantCulture));

private static void WriteInternal(Utf8JsonWriter writer, Time value)
=> writer.WriteStringValue($"{value.Hour}__{value.Minute}__{value.Second}");
=> writer.WriteStringValue(value.ToString());
}

0 comments on commit cf1c752

Please sign in to comment.