question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serialization/Deserialization of Metadata

See original GitHub issue

Hi,

I’m not sure this is an issue, but I’m struggling with deserialization metadata send using the method:

client.SendAndWait(metadata, totalMilliseconds, "my string");

Currently, I’m adding a class to the metadata dictionary. It’s a simple one, which should be serializable/de-serializable using Json.NET. The class in question has a few string properties, with a constructor sufficient for de-serialization again.

It looks similar to:

public class MyClass
{
        public MyClass(string property)
        {
            MyProperty = property ?? throw new ArgumentNullException(nameof(subscriptionFile));
        }

        public string Property { get; }
}

My understanding was that I should be able to add this as a value to the metadata dictionary on the client side, and then on the server side, it should be deserialized into my type again. (Going over the wire in JSON.)

What I see is that the metadata dictionary on the server side contains a JObject type which represents the original class as JSON, not an instance of the original concrete class.

From the JObject, I can call

o.ToObject<MyClass>()

Which turns it into my concrete object again.

Is there a reason I have to manually call ToObject on my metadata to deserialize it?

It’s not a particular pain, I just don’t want to be abusing how this otherwise brilliant framework should be used. 😃

Alternatively, would you recommend against using classes in the metadata dictionary?

Ta,

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jchristncommented, Nov 10, 2020

Also I’ll be sure to update the README on this one. Thanks for catching it.

0reactions
jchristncommented, Nov 9, 2020

Hi @code-pug I believe the reason this is happening and the reason you have to do a JObject.ToObject<[type]>... is because the metadata dictionary is defined as <object, object>. I’m glad you pointed this out, because I wasn’t aware this would happen.

I’ll leave this open in case anyone has a suggestion on how the library could be amended to allow the object to be deserialized automatically.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serialization and Metadata - UWP applications
In this article. If your app serializes and deserializes objects, you may need to add entries to your runtime directives (. rd. xml)...
Read more >
will serialized object contains metadata?
At a high level, the serialization stream contains the data inside the object and the name of the classes involved, as well as...
Read more >
Serializing metadata for use and reuse ✒️📋🗃️
Serialization. Data as it is stored on disk or transmitted on a wire is sent as a serial ordered list of bits and...
Read more >
Serialization/Deserialization protocol — registry-project latest ...
Serializer and Deserializer are used to marshal and unmarshal messages according to a given schema by adding schema version information either in the...
Read more >
Should serialize avoid emitting metadata on types that are ...
Deserialize : Cannot parse a JSON object containing metadata properties like '$id' into an array or immutable collection type. Type 'System.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found