Skip to content

Commit

Permalink
fix: csharp serializer incorrectly handles unwrappable dictionaries (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Aug 22, 2023
1 parent 627ed97 commit eb7dd62
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/generators/csharp/presets/JsonSerializerPreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ if (${modelInstanceVariable} != null) {
${renderSerializeProperty('unwrappedProperty.Value', propertyModel)}
}
}`;
}
serializeProperties += `if(${modelInstanceVariable} != null) {
} else {
serializeProperties += `if(${modelInstanceVariable} != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName("${propertyModel.unconstrainedPropertyName}");
${renderSerializeProperty(modelInstanceVariable, propertyModel)}
}\n`;
}
}
}
return serializeProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,8 @@ internal class TestConverter : JsonConverter<Test>
writer.WritePropertyName(unwrappedProperty.Key);
JsonSerializer.Serialize(writer, unwrappedProperty.Value, options);
}
}if(value.AdditionalProperties != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"additionalProperties\\");
JsonSerializer.Serialize(writer, value.AdditionalProperties, options);
}
writer.WriteEndObject();
}
Expand Down Expand Up @@ -292,13 +287,8 @@ internal class NestedTestConverter : JsonConverter<NestedTest>
writer.WritePropertyName(unwrappedProperty.Key);
JsonSerializer.Serialize(writer, unwrappedProperty.Value, options);
}
}if(value.AdditionalProperties != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"additionalProperties\\");
JsonSerializer.Serialize(writer, value.AdditionalProperties, options);
}
writer.WriteEndObject();
}
Expand Down

0 comments on commit eb7dd62

Please sign in to comment.