Weird serialization behaviour
See original GitHub issueConsider the following message definition in C#:
public interface CreateUser
{
string UserId { get; }
string UnverifiedPrimaryEmail { get; }
string Language { get; }
}
F# has explicit interface implementations. The syntax looks like this:
type CreateUserMsg(uid, email, lang) =
interface CreateUser with
member _.UserId = uid
member _.UnverifiedPrimaryEmail = lang
member _.Language = email
For some reason, instantiating and sending this will send a message where all the properties are null
.
As a counter-example, the following works fine:
type CreateUserMsg(uid, email, lang) =
member _.UserId = uid
member _.UnverifiedPrimaryEmail = email
member _.Language = lang
interface CreateUser with
member _.UserId = "some"
member _.UnverifiedPrimaryEmail = "other"
member _.Language = "value"
Note that if one of the non-interface members are removed or renamed, that member will be serialized to null
even though the interface contains the correct value. And that the actual (explicit) interface members are not used at all.
It might seem like MassTransit assumes the class itself contains members corresponding to those in the interface, and does not account for explicit interface implementations (which AFAIK is supported in C# too, by the way).
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Weird serialisation behavior with HashMap - java
This is a problem with circular initialisation. Whilst Java Serialisation can handle arbitrary cycles, the initialisation has to happen in ...
Read more >Odd serialization behaviour of UnityEvent inside an Editor ...
Hi Uniteers, I am observing a strange serialization behaviour for UnityEvents that I can't explain. Unity Events don't update their changes ...
Read more >Strange behaviour with serialisation after upgrade to 5.5
Hi, we were stable on 4.5 for a long time and recently went live, upgrading to 5.5 and started noticing random issues.
Read more >Weird serialization bug in prefab mode
In the external behavior tree we created all variables that are needed for the workings of that tree, and we planned on linking...
Read more >Mind-bending behavior for deserialization in Haskell
While that's weird behavior, it's also kind of weird code. Serialization is a major system boundary and thus needs to be done really ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Adapt this huge thing here? No thanks, that’s a maintenance burden I’d rather be without. I’ll look for other workarounds instead. 😃
For example, have C# contract projects where in addition to the message interfaces, I could add message classes implementing them. It’s not idiomatic, but it seems that’s the only way of sending strongly typed interface-based messages from F#, given the current serialization implementation.
Thanks for the help, though!
You can certainly create a new serializer by implementing the interfaces and adding it to the supported serializers/deserializers.
You can configure the entire bus instance (all receive endpoints) or a single receive endpoint to use a serializer, as well as support the deserializer, using:
That’s an example, you’d need your own content type. If you call:
That will remove all of the default serializer/deserializers.
(In this example, RawJsonMessageSerializer is an example – if you wanted to support System.Text.Json, I’d suggest using the built-in JsonMessageSerializer as a base).