Skip to content

Commit 033521c

Browse files
authored
Merge pull request abuzuhri#945 from ProNotion/fix/parameter-based-enum-member-serialisation-clean
fix(parameter-based): respect [EnumMember] attribute when serialising enum query parameters
2 parents 5ef1317 + 66e956a commit 033521c

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

Source/FikaAmazonAPI.SampleCode/FinancialSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public IList<Transaction> ListFinancialTransactions20240619_ByEventGroup(string
6565
new Parameter.Finance.ParameterListFinancialTransactions20240619()
6666
{
6767
postedAfter = DateTime.UtcNow.AddDays(-30),
68-
relatedIdentifierName = "FINANCIAL_EVENT_GROUP_ID",
68+
relatedIdentifierName = RelatedIdentifier.RelatedIdentifierNameEnum.FINANCIALEVENTGROUPID,
6969
relatedIdentifierValue = financialEventGroupId,
7070
});
7171
}

Source/FikaAmazonAPI/Parameter/Finance/ParameterListFinancialTransactions20240619.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public class ParameterListFinancialTransactions20240619 : ParameterBased
1919
/// </summary>
2020
public string? transactionStatus { get; set; }
2121
/// <summary>
22-
/// Possible values:`FINANCIAL_EVENT_GROUP_ID`: the financial event group ID associated with the transaction.
23-
///*Note: FINANCIAL_EVENT_GROUP_ID is the only `relatedIdentifier` with filtering capabilities at the moment. While other `relatedIdentifier` values will be included in the response when available, they cannot be used for filtering purposes.
22+
/// The identifier name to filter by. Only FINANCIAL_EVENT_GROUP_ID has filtering capability at the moment;
23+
/// other values appear in response payloads but cannot be used as query filters.
2424
/// </summary>
25-
public string? relatedIdentifierName { get; set; }
25+
public RelatedIdentifierNameEnum? relatedIdentifierName { get; set; }
2626
public string? relatedIdentifierValue { get; set; }
2727
public string nextToken { get; set; }
2828
public int? MaxNumberOfPages { get; set; }

Source/FikaAmazonAPI/Parameter/ParameterBased.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,22 @@ public virtual List<KeyValuePair<string, string>> getParameters()
5757
}
5858
else if (p.PropertyType.IsEnum || IsNullableEnum(p.PropertyType))
5959
{
60-
output = value.ToString();
60+
var enumSettings = new JsonSerializerSettings
61+
{
62+
Converters = new List<JsonConverter> { new StringEnumConverter() }
63+
};
64+
output = JsonConvert.SerializeObject(value, enumSettings).Trim('"');
6165
}
6266
else if (IsEnumerableOfEnum(p.PropertyType) || IsEnumerable(p.PropertyType))
6367
{
64-
var data = ((ICollection)value).Cast<object>().Select(a => a.ToString());
68+
var enumSettings = new JsonSerializerSettings
69+
{
70+
Converters = new List<JsonConverter> { new StringEnumConverter() }
71+
};
72+
var data = ((ICollection)value).Cast<object>()
73+
.Select(a => a.GetType().IsEnum
74+
? JsonConvert.SerializeObject(a, enumSettings).Trim('"')
75+
: a.ToString());
6576
if (data.Count() > 0)
6677
{
6778
var result = data.ToArray();

0 commit comments

Comments
 (0)