-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Utf8JsonReader\Writer should support all primitive types #29000
Comments
{Try}GetSingle exists already. Same with Therefore, I don't think we need custom code like this. @steveharter, please let me know if I am mistaken. New APIs: public ref partial struct Utf8JsonReader
{
public byte GetByte() { throw null; }
public sbyte GetSByte() { throw null; }
public short GetInt16() { throw null; }
public ushort GetUInt16() { throw null; }
public bool TryGetByte(out byte value) { throw null; }
public bool TryGetSByte(out sbyte value) { throw null; }
public bool TryGetInt16(out short value) { throw null; }
public bool TryGetUInt16(out ushort value) { throw null; }
public char GetChar() { throw null; }
public bool TryGetChar(out char value) { throw null; }
}
public readonly partial struct JsonElement
{
public byte GetByte() { throw null; }
public sbyte GetSByte() { throw null; }
public short GetInt16() { throw null; }
public ushort GetUInt16() { throw null; }
public bool TryGetByte(out byte value) { throw null; }
public bool TryGetSByte(out sbyte value) { throw null; }
public bool TryGetInt16(out short value) { throw null; }
public bool TryGetUInt16(out ushort value) { throw null; }
public char GetChar() { throw null; }
public bool TryGetChar(out char value) { throw null; }
}
public sealed partial class Utf8JsonWriter : IDisposable
{
// Not strictly needed since the int32 overload works as well.
public void WriteNumberValue(byte value) { }
public void WriteNumberValue(sbyte value) { }
public void WriteNumberValue(short value) { }
public void WriteNumberValue(ushort value) { }
// Not strictly needed since the int32 overload works as well.
public void WriteNumber(System.ReadOnlySpan<byte> utf8PropertyName, byte value) { }
public void WriteNumber(System.ReadOnlySpan<byte> utf8PropertyName, sbyte value) { }
public void WriteNumber(System.ReadOnlySpan<byte> utf8PropertyName, short value) { }
public void WriteNumber(System.ReadOnlySpan<byte> utf8PropertyName, ushort value) { }
public void WriteNumber(System.ReadOnlySpan<char> propertyName, byte value) { }
public void WriteNumber(System.ReadOnlySpan<char> propertyName, sbyte value) { }
public void WriteNumber(System.ReadOnlySpan<char> propertyName, short value) { }
public void WriteNumber(System.ReadOnlySpan<char> propertyName, ushort value) { }
public void WriteNumber(string propertyName, byte value) { }
public void WriteNumber(string propertyName, sbyte value) { }
public void WriteNumber(string propertyName, short value) { }
public void WriteNumber(string propertyName, ushort value) { }
public void WriteNumber(JsonEncodedText propertyName, byte value) { }
public void WriteNumber(JsonEncodedText propertyName, sbyte value) { }
public void WriteNumber(JsonEncodedText propertyName, short value) { }
public void WriteNumber(JsonEncodedText propertyName, ushort value) { }
// For single-char string, user can wrap it in a span.
public void WriteString(string propertyName, char value) { }
public void WriteString(JsonEncodedText propertyName, char value) { }
public void WriteString(System.ReadOnlySpan<char> propertyName, char value) { }
public void WriteString(System.ReadOnlySpan<byte> utf8PropertyName, char value) { }
public void WriteStringValue(char value) { }
} Open Questions:
Current workarounds within the serializer: Related issue: https://github.com/dotnet/corefx/issues/34690 cc @GrabYourPitchforks - if you have thoughts on surrogate pair behavior. |
For the writer, these values are already covered by the implicit conversions to int. I don't know what it means to write a single For the reader there's arguably benefit for the Try APIs on the smaller numeric types... I could go either way. Again, I don't know what it means for |
Agreed. I don't mind removing it from the writer.
Yep. I think having it on the reader makes more sense.
I had the same question. @steveharter, any thoughts? Otherwise, we can discuss in the review itself. |
The float\single converter in the serializer now uses the appropriate reader API. I'll update the issue. For |
The
The other ones seem fine. |
@steveharter @ahsonkhan is this something that I can start working on while the conclusion is reached on API for In that case I could start with |
@WinCPP, sound good to me. Assigning to you. Thanks. |
@ahsonkhan I followed the steps given in updating-ref-source.md to add new
Looks like the steps in doc are no more being followed? And instead should I directly add the methods by hand? Appreciate your inputs. |
This is a known limitation and requires a manual change to remove (currently the DisposeAsync API surface is within the manual ref since the API surface is different between platforms).
Can you file an issue regarding this in arcade - https://github.com/dotnet/arcade/issues? I am not sure if this is expected (maybe related to recent changes like dotnet/arcade#2526).
Sure, if that's easier. One thing you could do is generate the ref to see the fully qualified API surface and what order they should appear in, undo all the other changes, and manually re-add the new APIs. Other than having to deal with some corner cases (for instance where the manual ref file is involved), it should generally work. |
Can we fix that? |
@ahsonkhan Additions for (Try)Get for byte, sbyte, short, ushort are almost ready.
|
They are not yet needed, and can be added later (especially after some perf validation related to up-casting to a larger numeric type).
I'll follow up on that and get back to you.
This is the issue. If you look at the API proposal, these APIs need to be added to |
Oops sorry. How did I miss that 🤦♂️ : Will will on the same. |
* CoreFx #36125 (Try)Get for byte sbyte short ushort * Init out values on failure return paths. * APIs in JsonElement and related tests * More test cases, test bug fixes, code fixes
We concluded we shouldn't support it unless there is significant customer feedback. |
To be clear, the conclusion was we wouldn't support |
now that all primitive types are supported (thanks to dotnet#29000), we can remove custom bound checks.
now that all primitive types are supported (thanks to #29000), we can remove custom bound checks.
Currently these primitive types are not directly supported and must have custom code to use, such as what the JsonSerializer currently does:
cc @ahsonkhan
The text was updated successfully, but these errors were encountered: