diff --git a/backend/src/Designer/Helpers/JsonConverterHelpers/OptionConverterHelper.cs b/backend/src/Designer/Helpers/JsonConverterHelpers/OptionConverterHelper.cs index 9ba74b172ef..0c5d23b207d 100644 --- a/backend/src/Designer/Helpers/JsonConverterHelpers/OptionConverterHelper.cs +++ b/backend/src/Designer/Helpers/JsonConverterHelpers/OptionConverterHelper.cs @@ -26,14 +26,17 @@ public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOp case string s: writer.WriteStringValue(s); break; - case double d: - writer.WriteNumberValue(d); + case double: + case int: + case long: + case decimal: + writer.WriteNumberValue(Convert.ToDouble(value)); break; case bool b: writer.WriteBooleanValue(b); break; default: - throw new InvalidOptionsFormatException($"{value} is an unsupported type for Value field. Accepted types are string, double and bool."); + throw new InvalidOptionsFormatException($"{value} is an unsupported type for Value field. Accepted types are string, numbers and bool."); } } } diff --git a/backend/tests/Designer.Tests/Controllers/OptionsController/UpdateOptionsTests.cs b/backend/tests/Designer.Tests/Controllers/OptionsController/UpdateOptionsTests.cs index 28a3fbad16b..0b6fa37c012 100644 --- a/backend/tests/Designer.Tests/Controllers/OptionsController/UpdateOptionsTests.cs +++ b/backend/tests/Designer.Tests/Controllers/OptionsController/UpdateOptionsTests.cs @@ -63,7 +63,7 @@ public async Task Put_Returns_200OK_When_Creating_New_OptionsList() } [Fact] - public async Task Put_Returns_200OK_When_Option_Values_Are_Bool_String_Double() + public async Task Put_Returns_200OK_When_Option_Values_Are_Bool_String_Numbers() { string repo = "app-with-options"; string optionsListId = "test-options"; @@ -74,12 +74,13 @@ public async Task Put_Returns_200OK_When_Option_Values_Are_Bool_String_Double() string apiUrl = $"/designer/api/{Org}/{targetRepository}/options/{optionsListId}"; using HttpRequestMessage httpRequestMessage = new(HttpMethod.Put, apiUrl); - var stringBoolDoubleOptionsList = @"[ + var stringBoolNumbersOptionsList = @"[ { ""label"": ""StringValue"", ""value"": ""value"" }, { ""label"": ""BoolValue"", ""value"": true }, { ""label"": ""NumberValue"", ""value"": 3.1415 }, + { ""label"": ""NumberValue"", ""value"": 1024 }, ]"; - httpRequestMessage.Content = new StringContent(stringBoolDoubleOptionsList, Encoding.UTF8, "application/json"); + httpRequestMessage.Content = new StringContent(stringBoolNumbersOptionsList, Encoding.UTF8, "application/json"); // Act using HttpResponseMessage response = await HttpClient.SendAsync(httpRequestMessage);