Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Can not deserialize class having property as byte[] #229

Open
MittalNitish opened this issue Aug 21, 2020 · 0 comments
Open

Can not deserialize class having property as byte[] #229

MittalNitish opened this issue Aug 21, 2020 · 0 comments

Comments

@MittalNitish
Copy link

Using version: 1.3.7

When I am trying to deserialize the following JSON : {"Body":[123,34,72,105,115,116,111,114,121,83,97,109,112],"Properties":{"key":"0bf5f58a-1d20-415c-8b1d-21cb801dbe40"}}
to following type:

public class Custom
{
    public byte[] Body { get; set; }
    public Dictionary<string, object> Properties { get; set; }
}

it fails with error:

Utf8Json.JsonParsingException: expected:'String Begin Token', actual:'[', at offset:8
   at Utf8Json.JsonReader.ReadStringSegmentCore(Byte[]& resultBytes, Int32& resultOffset, Int32& resultLength)
   at Utf8Json.JsonReader.ReadString()
   at Utf8Json.Formatters.ByteArrayFormatter.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
   at Utf8Json.Formatters.utf8tests_CustomFormatter1.Deserialize(JsonReader& , IJsonFormatterResolver )
   at Utf8Json.JsonSerializer.Deserialize[T](Byte[] bytes, Int32 offset, IJsonFormatterResolver resolver)
   at Utf8Json.JsonSerializer.Deserialize[T](Byte[] bytes, IJsonFormatterResolver resolver)
   at Utf8Json.JsonSerializer.Deserialize[T](String json, IJsonFormatterResolver resolver)
   at Utf8Json.JsonSerializer.Deserialize[T](String json)
   at utf8tests.Program.Main(String[] args) in C:\HelperPrograms\utf8tests\utf8tests\Program.cs:line 21

However, it works if I change the the type to IList, ex:

public class Custom
{
    public IList<byte> Body { get; set; }
    public Dictionary<string, object> Properties { get; set; }
}

We do not want to use IList for the Body property. Is there a way we can make it work using array itself?

Attaching sample to reproduce issue
utf8tests.zip
.

AMPing added a commit to AMPing/ZCS.Utf8Json that referenced this issue Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant