-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Text.JsonwishlistIssue we would like to prioritize, but we can't commit we will get to it yetIssue we would like to prioritize, but we can't commit we will get to it yet
Milestone
Description
Background and motivation
Currently System.Text.Json has no support for serializing BigInteger values. This is a proposal for serializing BigInteger values as arbitrarily sized JSON numbers.
API Proposal
namespace System.Text.Json
{
public ref partial struct Utf8JsonReader
{
+ public BigInteger GetBigInteger();
+ public bool TryGetBigInteger(out BigInteger value);
}
public sealed partial class Utf8JsonWriter
{
+ public void WriteNumber(JsonEncodedText propertyName, BigInteger value);
+ public void WriteNumber(string propertyName, BigInteger value);
+ public void WriteNumber(ReadOnlySpan<char> propertyName, BigInteger value);
+ public void WriteNumber(ReadOnlySpan<byte> utf8PropertyName, BigInteger value);
+ public void WriteNumberValue(BigInteger value);
}
public readonly partial struct JsonElement
{
+ public BigInteger GetBigInteger();
+ public bool TryGetBigInteger(out BigInteger value)
}
}
namespace System.Text.Json.Node
{
public abstract partial class JsonNode
{
+ public static explicit operator BigInteger(JsonNode value);
+ public static explicit operator BigInteger?(JsonNode? value);
+ public static implicit operator JsonNode(BigInteger value);
+ public static implicit operator JsonNode?(BigInteger? value);
}
}
namespace System.Text.Json.Serialization.Metadata
{
public static partial class JsonMetadataServices
{
+ public static JsonConverter<BigInteger> BigIntegerConverter { get; }
}
}API Usage
JsonSerializer.Serialize((BigInteger)42);
// Current JSON: {"IsPowerOfTwo":false,"IsZero":false,"IsOne":false,"IsEven":true,"Sign":1}
// New JSON: 42Alternative Designs
No response
Risks
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Text.JsonwishlistIssue we would like to prioritize, but we can't commit we will get to it yetIssue we would like to prioritize, but we can't commit we will get to it yet