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

Add the ability to serialize enums values #1898

Merged
merged 5 commits into from
May 4, 2022
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
3 changes: 3 additions & 0 deletions src/ApiService/ApiService/OneFuzzTypes/Enums.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Collections.Concurrent;
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;

namespace Microsoft.OneFuzz.Service;

[SerializeValue]
public enum ErrorCode {
INVALID_REQUEST = 450,
INVALID_PERMISSION = 451,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public async Task<HttpResponseData> MarkTasksStoppedEarly([HttpTrigger(Authoriza

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

var resp = req.CreateResponse(HttpStatusCode.OK);
return resp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Microsoft.OneFuzz.Service.OneFuzzLib.Orm;

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

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