Skip to content

Commit 936d073

Browse files
authored
feat(common): support null value for reference type collection elements (#3163)
- update `SerializationBuilder` to set `ValueSerialization.IsNullable : true` for reference type collection elements - that will add null value handling in deserialization logic for collection elements of reference type - generate null check in generated serialization/deserialization codes for: - nullable value type - list/dictionary types - some framework reference types - optimize null value processing so that we don't generate null check codes - for custom model types, put null value processing logic into the deserialization method of each model - for string, use default serialization/deserialization methods which can handle null value - update `byte[]` serializatoin/deserialization methods so that they can handle null value, so that we don't generate null check codes externally - fix 3 test cases previously do not accept null value in collections in response, now we align with other language implementaion on that resolve #3159
1 parent ec012c6 commit 936d073

File tree

1,363 files changed

+6085
-256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,363 files changed

+6085
-256
lines changed

samples/AnomalyDetector/Generated/Models/AlignPolicy.Serialization.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
5757

5858
internal static AlignPolicy DeserializeAlignPolicy(JsonElement element)
5959
{
60+
if (element.ValueKind == JsonValueKind.Null)
61+
{
62+
return null;
63+
}
6064
Optional<AlignMode?> alignMode = default;
6165
Optional<FillNAMethod?> fillNAMethod = default;
6266
Optional<float?> paddingValue = default;

samples/AnomalyDetector/Generated/Models/AnomalyDetectionModel.Serialization.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public partial class AnomalyDetectionModel
1616
{
1717
internal static AnomalyDetectionModel DeserializeAnomalyDetectionModel(JsonElement element)
1818
{
19+
if (element.ValueKind == JsonValueKind.Null)
20+
{
21+
return null;
22+
}
1923
string modelId = default;
2024
DateTimeOffset createdTime = default;
2125
DateTimeOffset lastUpdatedTime = default;

samples/AnomalyDetector/Generated/Models/AnomalyInterpretation.Serialization.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public partial class AnomalyInterpretation
1515
{
1616
internal static AnomalyInterpretation DeserializeAnomalyInterpretation(JsonElement element)
1717
{
18+
if (element.ValueKind == JsonValueKind.Null)
19+
{
20+
return null;
21+
}
1822
Optional<string> variable = default;
1923
Optional<float?> contributionScore = default;
2024
Optional<CorrelationChanges> correlationChanges = default;

samples/AnomalyDetector/Generated/Models/AnomalyState.Serialization.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public partial class AnomalyState
1717
{
1818
internal static AnomalyState DeserializeAnomalyState(JsonElement element)
1919
{
20+
if (element.ValueKind == JsonValueKind.Null)
21+
{
22+
return null;
23+
}
2024
DateTimeOffset timestamp = default;
2125
Optional<AnomalyValue> value = default;
2226
Optional<IReadOnlyList<ErrorResponse>> errors = default;

samples/AnomalyDetector/Generated/Models/AnomalyValue.Serialization.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public partial class AnomalyValue
1616
{
1717
internal static AnomalyValue DeserializeAnomalyValue(JsonElement element)
1818
{
19+
if (element.ValueKind == JsonValueKind.Null)
20+
{
21+
return null;
22+
}
1923
bool isAnomaly = default;
2024
float severity = default;
2125
float score = default;

samples/AnomalyDetector/Generated/Models/CorrelationChanges.Serialization.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public partial class CorrelationChanges
1616
{
1717
internal static CorrelationChanges DeserializeCorrelationChanges(JsonElement element)
1818
{
19+
if (element.ValueKind == JsonValueKind.Null)
20+
{
21+
return null;
22+
}
1923
Optional<IReadOnlyList<string>> changedVariables = default;
2024
foreach (var property in element.EnumerateObject())
2125
{

samples/AnomalyDetector/Generated/Models/DiagnosticsInfo.Serialization.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
3737

3838
internal static DiagnosticsInfo DeserializeDiagnosticsInfo(JsonElement element)
3939
{
40+
if (element.ValueKind == JsonValueKind.Null)
41+
{
42+
return null;
43+
}
4044
Optional<ModelState> modelState = default;
4145
Optional<IList<VariableState>> variableStates = default;
4246
foreach (var property in element.EnumerateObject())

samples/AnomalyDetector/Generated/Models/ErrorResponse.Serialization.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
2525

2626
internal static ErrorResponse DeserializeErrorResponse(JsonElement element)
2727
{
28+
if (element.ValueKind == JsonValueKind.Null)
29+
{
30+
return null;
31+
}
2832
string code = default;
2933
string message = default;
3034
foreach (var property in element.EnumerateObject())

samples/AnomalyDetector/Generated/Models/ModelInfo.Serialization.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
8080

8181
internal static ModelInfo DeserializeModelInfo(JsonElement element)
8282
{
83+
if (element.ValueKind == JsonValueKind.Null)
84+
{
85+
return null;
86+
}
8387
string dataSource = default;
8488
Optional<DataSchema?> dataSchema = default;
8589
DateTimeOffset startTime = default;

samples/AnomalyDetector/Generated/Models/ModelState.Serialization.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
6262

6363
internal static ModelState DeserializeModelState(JsonElement element)
6464
{
65+
if (element.ValueKind == JsonValueKind.Null)
66+
{
67+
return null;
68+
}
6569
Optional<IList<int>> epochIds = default;
6670
Optional<IList<float>> trainLosses = default;
6771
Optional<IList<float>> validationLosses = default;

0 commit comments

Comments
 (0)