Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #173 from microsoft/andrueastman/fixDecimals
Browse files Browse the repository at this point in the history
Fixed a bug where serialization of decimal values would write them as empty objects.
  • Loading branch information
andrueastman authored Jan 29, 2024
2 parents c17b152 + b0150d5 commit 8ff3560
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.3] - 2024-01-29

### Changed

- Fixed a bug where serialization of decimal values would write them as empty objects.

### Added

## [1.1.2] - 2023-11-15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public void WritesSampleObjectValue()
WorkDuration = TimeSpan.FromHours(1),
StartWorkTime = new Time(8, 0, 0),
BirthDay = new Date(2017, 9, 4),
HeightInMetres = 1.80m,
AdditionalData = new Dictionary<string, object>
{
{"mobilePhone",null}, // write null value
{"accountEnabled",false}, // write bool value
{"jobTitle","Author"}, // write string value
{"createdDateTime", DateTimeOffset.MinValue}, // write date value
{"weightInKgs", 51.80m}, // write weigth
{"businessPhones", new List<string>() {"+1 412 555 0109"}}, // write collection of primitives value
{"endDateTime", new DateTime(2023,03,14,0,0,0,DateTimeKind.Utc) }, // ensure the DateTime doesn't crash
{"manager", new TestEntity{Id = "48d31887-5fad-4d73-a9f5-3c356e68a038"}}, // write nested object value
Expand All @@ -45,11 +47,13 @@ public void WritesSampleObjectValue()
"\"id\":\"48d31887-5fad-4d73-a9f5-3c356e68a038\"," +
"\"workDuration\":\"PT1H\","+ // Serializes timespans
"\"birthDay\":\"2017-09-04\"," + // Serializes dates
"\"heightInMetres\":1.80,"+
"\"startWorkTime\":\"08:00:00\"," + //Serializes times
"\"mobilePhone\":null," +
"\"accountEnabled\":false," +
"\"jobTitle\":\"Author\"," +
"\"createdDateTime\":\"0001-01-01T00:00:00+00:00\"," +
"\"weightInKgs\":51.80,"+
"\"businessPhones\":[\"\\u002B1 412 555 0109\"]," +
"\"endDateTime\":\"2023-03-14T00:00:00+00:00\"," +
"\"manager\":{\"id\":\"48d31887-5fad-4d73-a9f5-3c356e68a038\"}" +
Expand Down
4 changes: 4 additions & 0 deletions Microsoft.Kiota.Serialization.Json.Tests/Mocks/TestEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class TestEntity : IParsable, IAdditionalDataHolder
/// <summary>Read-only.</summary>
public DateTimeOffset? CreatedDateTime { get; set; }
/// <summary>Read-only.</summary>
public decimal? HeightInMetres { get; set; }
/// <summary>Read-only.</summary>
public string OfficeLocation { get; set; }
/// <summary>
/// Instantiates a new entity and sets the default values.
Expand All @@ -46,6 +48,7 @@ public virtual IDictionary<string, Action<IParseNode>> GetFieldDeserializers()
{"createdDateTime", n => { CreatedDateTime = n.GetDateTimeOffsetValue(); } },
{"officeLocation", n => { OfficeLocation = n.GetStringValue(); } },
{"workDuration", n => { WorkDuration = n.GetTimeSpanValue(); } },
{"heightInMetres", n => { HeightInMetres = n.GetDecimalValue(); } },
{"birthDay", n => { BirthDay = n.GetDateValue(); } },
{"startWorkTime", n => { StartWorkTime = n.GetTimeValue(); } },
{"endWorkTime", n => { EndWorkTime = n.GetTimeValue(); } },
Expand All @@ -65,6 +68,7 @@ public virtual void Serialize(ISerializationWriter writer)
writer.WriteStringValue("officeLocation", OfficeLocation);
writer.WriteTimeSpanValue("workDuration", WorkDuration);
writer.WriteDateValue("birthDay", BirthDay);
writer.WriteDecimalValue("heightInMetres", HeightInMetres);
writer.WriteTimeValue("startWorkTime", StartWorkTime);
writer.WriteTimeValue("endWorkTime", EndWorkTime);
writer.WriteAdditionalData(AdditionalData);
Expand Down
3 changes: 3 additions & 0 deletions src/JsonSerializationWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ private void WriteAnyValue<T>(string? key, T value)
case double d:
WriteDoubleValue(key, d);
break;
case decimal dec:
WriteDecimalValue(key, dec);
break;
case Guid g:
WriteGuidValue(key, g);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Kiota.Serialization.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageProjectUrl>https://aka.ms/kiota/docs</PackageProjectUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<VersionPrefix>1.1.2</VersionPrefix>
<VersionPrefix>1.1.3</VersionPrefix>
<VersionSuffix></VersionSuffix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down

0 comments on commit 8ff3560

Please sign in to comment.