Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit c07a908

Browse files
authored
Add the ability to serialize enums values (#1898)
* Add the ablility to serialize enums values * unit test
1 parent b2399c4 commit c07a908

File tree

5 files changed

+325
-290
lines changed

5 files changed

+325
-290
lines changed

src/ApiService/ApiService/OneFuzzTypes/Enums.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System.Collections.Concurrent;
2+
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
23

34
namespace Microsoft.OneFuzz.Service;
5+
6+
[SerializeValue]
47
public enum ErrorCode {
58
INVALID_REQUEST = 450,
69
INVALID_PERMISSION = 451,

src/ApiService/ApiService/TestHooks/NodeOperationsTestHooks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public async Task<HttpResponseData> MarkTasksStoppedEarly([HttpTrigger(Authoriza
268268

269269
var s = await req.ReadAsStringAsync();
270270
var markTasks = JsonSerializer.Deserialize<MarkTasks>(s!, EntityConverter.GetJsonSerializerOptions());
271-
await _nodeOps.MarkTasksStoppedEarly(markTasks.node, markTasks.error);
271+
await _nodeOps.MarkTasksStoppedEarly(markTasks!.node, markTasks.error);
272272

273273
var resp = req.CreateResponse(HttpStatusCode.OK);
274274
return resp;

src/ApiService/ApiService/onefuzzlib/orm/CustomConverterFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
99

1010
public sealed class CustomEnumConverterFactory : JsonConverterFactory {
11-
public override bool CanConvert(Type typeToConvert) => typeToConvert.IsEnum;
11+
public override bool CanConvert(Type typeToConvert) => typeToConvert.IsEnum && (typeToConvert.GetCustomAttribute<SerializeValueAttribute>() == null);
1212

1313
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) {
1414
object[]? knownValues = null;

0 commit comments

Comments
 (0)