-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
Complex Model Serilization Key Is Duplicated Issue With Key Attirubute #1683
Comments
Use of the Also consider:
|
I appreciate for fast reply and good tricks. I got it now. I have almost 4000 models in my project and I don't want to add the key attribute for all complex models. I think it's a risk for key maching. So, are there alternative solutions to serialize and deserialize complex models with the base model or without the Key property in the message pack ? |
You can use You could also try the "contractless" approach (search README for contractless), which can serialize classes with no attributes at all. But in my experience it's not particularly good. If it happens to do exactly what you need, then that's great. |
You could also try the "contractless" approach (search README for contractless), which can serialize classes with no attributes at all. I tried KeyAttirubute (with the use of duplicated key 99 like example code),[MessagePackObject(true)], contractless. Also, I disabled the double attribute and deleted the serializable attribute at your suggestion. Considering all these changes, I have benchmarks with the same data for different situations.I want to share my observation with you.
2.I agree with you. I can use [MessagePackObject(true)] that to ensure a manageable model structure. Also, it didn't affect operation time more than binaryformatter. 3.I noticed that for the 10 megabyte sample data generated recursively, the messagepack spends more operation time than the binary formatter for both [Key] and [MessagePackObject(true)]. According to the benchmark data, what do you think about that? Has the messagepack chunk feature or other options for big data ? What would be your suggestion? I appreciate your support and experience KeyAttirubute Benchmark Model Data Model Data [MessagePackObject(true)] Benchmark Model Data Model Data |
The binary formatter mostly just copies memory, whereas msgpack prescribes a variety of formats that are interoperable, so it's understandable that msgpack may be slower than binary formatter. If you want raw speed (something more akin to BinaryFormatter), you may want to check out https://github.com/Cysharp/MemoryPack. |
Thanks for your all support. I checked and tested the memory pack and it's faster than the binary formatter. But as far as I understood it doesn't support some types such as dynamic objects etc and I couldn't run memorypack with .net 5. Also, The memory pack implementation is harder than the message pack for me. Therefore I going to continue with the memory pack. I have last one question about the message pack. I noticed that the message pack's first running time was longer than the other running times. I have working time with the same data and shared it below. 4 MB What is the reason for the differences in the operation times in the messagepack? I cache some data and these data cannot be serialized again after the first run, which causes me to lose the advantage of messagepack. |
Two things make it slower the first time:
Most of the time typically goes to the first of these. You can avoid much of the first time hit by generating formatters ahead of time. Check out our README's AOT sections for how to accomplish this. |
Bug description
I have the complex model and I added key attributes for all model properties. But the Baseclass has ID property and all models got inheritance from it. Also, TestMainModel has other sub-models inherited from BaseClass.
As far as I understand all models got an inheritance from the base class that same Key attribute for the Id property. That's why when I tried to serialize the model, I got the Key Is Duplicated Issue.
key is duplicated, all members key must be unique. type: ModelBase member:Id
I tried to solve the issue with CustomResolver.But it didn't work for it.
Repro steps
Expected behavior
When I set the Key attribute for base class properties, The classes inherited from BaseModel can be used on the same model and don't get any duplicated Id issues.
So If I can define the Key attributes like that below, In my opinion, the messagepack doesn't throw exceptions.
The text was updated successfully, but these errors were encountered: