1

While the title is straight to the point, the problem has a weird aspect as well. So I have two solutions; D4T and Jangers. I am trying the same (de)serialization code in both solutions. I also made sure that all references are the same and that the object used are all in the same namespaces and everything.

Now, in Jangers I use the following code for serialization:

PropertySet propertySet = new PropertySet();
propertySet.SetProperty("T", new Vector(12, 13, 14));

//PropertySet
var serializePropertySet = Newtonsoft.Json.JsonConvert.SerializeObject(propertySet, Formatting.Indented);
PropertySet deserializePropertySet = Newtonsoft.Json.JsonConvert.DeserializeObject<PropertySet>(serializePropertySet);

The json in serializePropertySetis the following:

{
  "$type": "Core.PropertySet, Connectivity.DataModel",
  "T": {
    "X": 12.0,
    "Y": 13.0,
    "Z": 14.0
  }
}

And it also deserializes properly.

However, if I try the exact same code in D4T, the X, Y and Z are empty and they seem to be arrays.

{
  "$type": "Core.PropertySet, Connectivity.DataModel",
  "T": {
    "$type": "Newtonsoft.Json.Linq.JObject, Newtonsoft.Json",
    "X": {
      "$type": "Newtonsoft.Json.Linq.JValue, Newtonsoft.Json",
      "$values": []
    },
    "Y": {
      "$type": "Newtonsoft.Json.Linq.JValue, Newtonsoft.Json",
      "$values": []
    },
    "Z": {
      "$type": "Newtonsoft.Json.Linq.JValue, Newtonsoft.Json",
      "$values": []
    }
  }
}

What could be the cause? How can I make a workaround to make it work in the second solution as well?

EDIT: This is how it looks when debugging:

enter image description here

  • Can you show `PropertySet` and `Vector` classes? Also check if you have global serialization settings set somewhere: `JsonConvert.DefaultSettings = () =>...` – Artur Apr 04 '21 at 06:51
  • @Artur Thanks for your comment! I will try to set the global serialization settings as you suggested. As for the classes, I would have done that if the privacy rules would have allowed me to. But tell me which part of these classes would be of interest to you and perhaps I could edit the original post accordingly, without sensitive data. –  Apr 05 '21 at 06:42
  • I didn't ask to set global settings, I ask to check if it already set. And I'm pretty sure it is because there is `"$type"` property in your json but you don't pass second parameter to `SerializeObject` method. It means `TypeNameHandling` set to `TypeNameHandling.Auto` somewhere. Btw if this json afterword consumed by your API from outside world you have [security vulnerability](https://stackoverflow.com/questions/55924299/insecure-deserialization-using-json-net) – Artur Apr 05 '21 at 13:37
  • What I need from your classes is property definitions and method overrides like `ToString`, `Equels` and `GetHashCode` – Artur Apr 05 '21 at 13:38

0 Answers0