0

If have the Abstract type TransportsystemActionDTO, now I serialize a Object and get the following JSON:

  {
  "$id": "1",
  "$type": "MCC.MFCV2.Services.TransportService2Interfaces.Actions.GenerateGlobalTaskActionDTO, MCC.MFCV2.Services.TransportService2Interfaces",
  "Destination": "BA41",
  "Source": "BA11",
  "Description": "BA11->BA41",
  "UseCurrentResource": false,
  "ResourceType": null,
  "Priority": 0,
  "TypeOfTask": 1,
  "NextTransportsystemAction": {
    "$id": "2",
    "$type": "MCC.MFCV2.Services.TransportService2Interfaces.Actions.TriggerGenerateLocalTaskActionDTO, MCC.MFCV2.Services.TransportService2Interfaces",
    "Trigger": true,
    "ReTrigger": true,
    "NextTransportsystemAction": null,
    "ConfiguratorPosition": {
      "X": 110.0,
      "Y": 235.0,
      "Width": 187.42666666666668,
      "Height": 41.0,
      "Z": 0,
      "Layer": 0
    }
  },
  "ConfiguratorPosition": {
    "X": 105.0,
    "Y": 125.0,
    "Width": 192.23666666666682,
    "Height": 62.000000000000014,
    "Z": 0,
    "Layer": 0
  }
}

now the Problem is, when I desrialize with TransportsystemActionDTO as base Type, I got the following exception:

Could not create an instance of type MCC.MFCV2.Services.TransportService2Interfaces.Actions.TransportsystemActionDTO. Type is an interface or abstract class and cannot be instantiated.

It is ok, but I don't know what the base Type is, that can be different Types, but the Type is stored in the $type field, so the Deserialisation should be possible...

1
  • Why is TransportsystemActionDTO abstract? make it a concrete class. Commented Jan 12, 2014 at 14:23

1 Answer 1

1

Found my error. I Added TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto to Serialisation, but not to Deserialisation. Now it's working!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.