Skip to content

Commit

Permalink
Ensure that JsonHelper.FindChangedFields does not return BigInteger
Browse files Browse the repository at this point in the history
Big integer is not supported in json becuase it serialized on the usless form
{"IsPowerOfTwo":true,"IsZero":false,"IsOne":false,"IsEven":true,"Sign":1}
  • Loading branch information
ivarne committed Dec 14, 2022
1 parent cc5f8ca commit 4eda33a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Altinn.App.Core/Helpers/JsonHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable

using System.Numerics;
using Altinn.App.Core.Features;
using Altinn.Platform.Storage.Interface.Models;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -182,7 +183,13 @@ private static void FindDiff(Dictionary<string, object?> dict, JToken? old, JTok
break;

default:
dict.Add(prefix, current == null ? null : ((JValue)current).Value);
var convertedValue = (current as JValue)?.Value switch
{
// BigInteger is not supported in json, so try to reduce to decimal, if possible, or string if too big
BigInteger bigInt => bigInt <= new BigInteger(decimal.MaxValue) ? (decimal)bigInt : bigInt.ToString(System.Globalization.NumberFormatInfo.InvariantInfo),
_ => (current as JValue)?.Value
};
dict.Add(prefix, convertedValue);
break;
}
}
Expand Down

0 comments on commit 4eda33a

Please sign in to comment.