Fix handling of readonly private fields#1267
Fix handling of readonly private fields#1267AArnott merged 1 commit intoMessagePack-CSharp:developfrom
Conversation
Disallow writing to readonly private fields even when using a resolver that allows using private fields. Fixes: MessagePack-CSharp#1218
|
This regressed #1308. I'm looking for a mutually acceptable solution. |
|
This change unfortunately broke deserializing for many of our objects. Is there any way to restore the ability to set the values of readonly fields without having to create custom constructors for each object? For example, this is what an object might look like: Before MessagePack 2.3.75 this worked, but after 2.3.75 the Code field is always empty after deserializing. What is the best way to get this working again? Thanks! |
|
IMHO; this shouldn't work. I expect serializer libraries to maintain the "readonly" constraints set by the compiler. The fact that message-pack was writing to readonly fields came as a big surprise to me. Also, @RobotGizmo, how on earth is that |
|
I think our issue is that we view the serializer as something that dumps the data from an object then puts it back in blindly. If there is a field with data it should be filled in again unless it's marked with The example above was just a part of the code as a sample, we do have a public constructor as well, like this: |
|
@RobotGizmo #1314 already corrected the regression. Can you confirm? |
|
@AArnott Thanks, it looks like it's working as it did before with v2.3.85. :) |
Disallow writing to readonly private fields even when using a resolver
that allows using private fields.
Fixes: #1218