Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: problem with json serializer option with C# generator #1477

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal class RootConverter : JsonConverter<Root>

writer.WriteStartObject();

if(value.Email != null) {
if(value.Email != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"email\\");
JsonSerializer.Serialize(writer, value.Email, options);
Expand Down
6 changes: 3 additions & 3 deletions src/generators/csharp/presets/JsonSerializerPreset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function renderSerializeProperty(
model.property instanceof ConstrainedReferenceModel &&
model.property.ref instanceof ConstrainedEnumModel
) {
value = `${model.property.type}.GetValue()`;
value = `value.${model.property.type}.GetValue()`;
}
return `JsonSerializer.Serialize(writer, ${value}, options);`;
}
Expand Down Expand Up @@ -51,7 +51,7 @@ if (${modelInstanceVariable} != null) {
}
}`;
}
serializeProperties += `if(${modelInstanceVariable} != null) {
serializeProperties += `if(${modelInstanceVariable} != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName("${propertyModel.unconstrainedPropertyName}");
${renderSerializeProperty(modelInstanceVariable, propertyModel)}
Expand Down Expand Up @@ -123,7 +123,7 @@ function renderDeserializeProperty(model: ConstrainedObjectPropertyModel) {
model.property instanceof ConstrainedReferenceModel &&
model.property.ref instanceof ConstrainedEnumModel
) {
return `${model.property.name}Extension.To${model.property.name}(JsonSerializer.Deserialize<dynamic>(ref reader, options))`;
return `${model.property.name}Extensions.To${model.property.name}(JsonSerializer.Deserialize<dynamic>(ref reader, options))`;
}
return `JsonSerializer.Deserialize<${model.property.type}>(ref reader, options)`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal class TestConverter : JsonConverter<Test>
}
if (propertyName == \\"enumProp\\")
{
var value = EnumTestExtension.ToEnumTest(JsonSerializer.Deserialize<dynamic>(ref reader, options));
var value = EnumTestExtensions.ToEnumTest(JsonSerializer.Deserialize<dynamic>(ref reader, options));
instance.EnumProp = value;
continue;
}
Expand Down Expand Up @@ -114,22 +114,22 @@ internal class TestConverter : JsonConverter<Test>

writer.WriteStartObject();

if(value.StringProp != null) {
if(value.StringProp != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"string prop\\");
JsonSerializer.Serialize(writer, value.StringProp, options);
}
if(value.NumberProp != null) {
if(value.NumberProp != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"numberProp\\");
JsonSerializer.Serialize(writer, value.NumberProp, options);
}
if(value.EnumProp != null) {
if(value.EnumProp != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"enumProp\\");
JsonSerializer.Serialize(writer, EnumTest?.GetValue(), options);
JsonSerializer.Serialize(writer, value.EnumTest?.GetValue(), options);
}
if(value.ObjectProp != null) {
if(value.ObjectProp != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"objectProp\\");
JsonSerializer.Serialize(writer, value.ObjectProp, options);
Expand All @@ -147,7 +147,7 @@ internal class TestConverter : JsonConverter<Test>
writer.WritePropertyName(unwrappedProperty.Key);
JsonSerializer.Serialize(writer, unwrappedProperty.Value, options);
}
}if(value.AdditionalProperties != null) {
}if(value.AdditionalProperties != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"additionalProperties\\");
JsonSerializer.Serialize(writer, value.AdditionalProperties, options);
Expand Down Expand Up @@ -274,7 +274,7 @@ internal class NestedTestConverter : JsonConverter<NestedTest>

writer.WriteStartObject();

if(value.StringProp != null) {
if(value.StringProp != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"stringProp\\");
JsonSerializer.Serialize(writer, value.StringProp, options);
Expand All @@ -292,7 +292,7 @@ internal class NestedTestConverter : JsonConverter<NestedTest>
writer.WritePropertyName(unwrappedProperty.Key);
JsonSerializer.Serialize(writer, unwrappedProperty.Value, options);
}
}if(value.AdditionalProperties != null) {
}if(value.AdditionalProperties != null) {
// write property name and let the serializer serialize the value itself
writer.WritePropertyName(\\"additionalProperties\\");
JsonSerializer.Serialize(writer, value.AdditionalProperties, options);
Expand Down