From 42f25139be5f496c3e437d187bcf0fb9cbdcb58d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20C=C3=B4t=C3=A9?= Date: Tue, 15 Aug 2023 14:00:54 -0400 Subject: [PATCH] Fix problem with json serializer option --- .../csharp/presets/JsonSerializerPreset.ts | 4 ++-- .../JsonSerializerPreset.spec.ts.snap | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/generators/csharp/presets/JsonSerializerPreset.ts b/src/generators/csharp/presets/JsonSerializerPreset.ts index 578f9b3503..9179fc28e5 100644 --- a/src/generators/csharp/presets/JsonSerializerPreset.ts +++ b/src/generators/csharp/presets/JsonSerializerPreset.ts @@ -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);`; } @@ -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(ref reader, options))`; + return `${model.property.name}Extensions.To${model.property.name}(JsonSerializer.Deserialize(ref reader, options))`; } return `JsonSerializer.Deserialize<${model.property.type}>(ref reader, options)`; } diff --git a/test/generators/csharp/presets/__snapshots__/JsonSerializerPreset.spec.ts.snap b/test/generators/csharp/presets/__snapshots__/JsonSerializerPreset.spec.ts.snap index 793fc7fed8..ff361b1bf2 100644 --- a/test/generators/csharp/presets/__snapshots__/JsonSerializerPreset.spec.ts.snap +++ b/test/generators/csharp/presets/__snapshots__/JsonSerializerPreset.spec.ts.snap @@ -114,22 +114,22 @@ internal class TestConverter : JsonConverter 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); @@ -147,7 +147,7 @@ internal class TestConverter : JsonConverter 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); @@ -274,7 +274,7 @@ internal class NestedTestConverter : JsonConverter 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); @@ -292,7 +292,7 @@ internal class NestedTestConverter : JsonConverter 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);