Closed antomys closed 9 months ago
For example, there is code that i use for tests https://github.com/antomys/CuriousBenchmarks/blob/62dec337ea30f2414dc61ab687181f57c43a8768/Json/Json.Tests/NetJsonTests.cs#L18
Thanks for the detail breakdown. I will spend some time on going over it and get back to you.
On Tue, Jul 19, 2022, 7:23 AM Ihor Volokhovych @.***> wrote:
For example, there is code that i use for tests
— Reply to this email directly, view it on GitHub https://github.com/rpgmaker/NetJSON/issues/242#issuecomment-1189119423, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEIF33ZDVS6AMOT3KRAKG3VU226NANCNFSM54ACRZMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>
@antomys , after looking much into it. The issue here is not related to serialization but rather the use of camelCase properties in your payload. The CamelCase is only used for serialization (Formatting, similar to using Format.Prettify) and not deserialization.
Refer to wiki to currently available options - https://github.com/rpgmaker/NetJSON/wiki/Quick-Guide
If you look at the other output of deserialization, you will notice that all the properties has default values. The reason the date does not match is because you are getting the default value which is set to the current date of 7/19/2022.
To solve this problem, i will need to support use of camelCase for deserialization or you can simply use
new NetJsonSettings
{
CaseSensitive = false,
... (Other options you are currently using)
}
Example is the following:
[TestMethod]
public void TestPersonClassWithMultipleNonDefaultConstructor() {
var json = "{ \"name\": \"boss\", \"age\": 2, \"reasonForUnknownAge\": \"he is the boss\" }";
var data = NetJSON.Deserialize<PersonTest>(json, new NetJSONSettings { CaseSensitive = false });
Assert.IsTrue(data.Age == 2);
}
public class PersonTest {
public string Name { get; private set; }
public int? Age { get; private set; }
public string ReasonForUnknownAge { get; private set; }
public PersonTest(string name, int age) {
Age = age;
Name = name;
} // age is known
public PersonTest(string name, string reasonForUnknownAge) {
Name = name;
ReasonForUnknownAge = reasonForUnknownAge;
} // age is unknown, for some reason
}
Let me know if that make sense to you. Thanks
Thanks for the answer, @rpgmaker!
The so, for now i will be using standart properties name, without came case. I thought that option CamelCase = true
refers both to serialization and deserialization.
Tried to use it with CaseSensitive = false,
as you suggested, failing with OutOfMemoryException in same test case (see photo below). As for now, it is not a big problem, so i'll just stick with native pascalCase.
@antomys . Could you provide a full test project for me to repro the out of memory issue?
@rpgmaker sure. Here i created test project for you https://github.com/antomys/NetJsonOutOfMemoryException
In program.cs
placed todo above Deserialization method, that throws OutOfMemoryException. Thanks
Awesome. Thanks again. I will try it out and see what I can do.
Still looking into it. Strange that it is generating out of memory exception.
Sorry I have not made much progress on this changes yet. Been busy on a lot of other things. I have not dropped this.
Hi! That's okay, don't worry. I'll try to investigate it too when i'll have some tive
@antomys , This issue is already fixed in 1.4.3. It seem you are using a version from 2020. I will close this issue, let me know if you are still receiving the problem. Thanks
Hello
The problem is that it doesn't deserialize the date in ISO-8601 format ("testDate":"2021-11-11T21:34:09.8494988Z")
See example below:
(Top is what I expect. Bottom is deserialized)
Also using this NetJson settings:
Note: data above is generated with
Bogus
in universal format.See see example Json string:
So i do expect in this case date as :
But i do get from
NetJSON.NetJSON.Deserialize<T>(testString, JsonServiceExtensions.NetJsonOptions)
: