Skip to content

Commit

Permalink
Fix trailing comma when there are no features to analyze (#3438)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev authored Sep 12, 2023
1 parent 5b1a7c2 commit b10b865
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Realm/Realm.Weaver/Analytics/Analytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,20 @@ private string GetJsonPayload()

jsonPayload.Append('{');

AppendKeyValues(_realmEnvMetrics);
jsonPayload.Append(',');
AppendKeyValues(_realmFeaturesToAnalyze, Metric.SdkFeatures);
jsonPayload.Append(GetJsonString(_realmEnvMetrics));

var featuresString = GetJsonString(_realmFeaturesToAnalyze, Metric.SdkFeatures);
if (!string.IsNullOrEmpty(featuresString))
{
jsonPayload.Append(',');
jsonPayload.Append(featuresString);
}

jsonPayload.Append('}');

return jsonPayload.ToString();

void AppendKeyValues<TValue>(IDictionary<string, TValue> dict, IDictionary<string, string>? keyMapping = null)
string GetJsonString<TValue>(IDictionary<string, TValue> dict, IDictionary<string, string>? keyMapping = null)
{
var mapping = dict
.Select(kvp =>
Expand All @@ -495,7 +501,7 @@ void AppendKeyValues<TValue>(IDictionary<string, TValue> dict, IDictionary<strin
})
.Where(s => s != null);

jsonPayload.Append(string.Join(",", mapping));
return string.Join(",", mapping);
}
}

Expand Down

0 comments on commit b10b865

Please sign in to comment.