Asaad Mamoun Asaad Mamoun - 5 months ago 19
JSON Question

Deserialize Facebook Workplace SCIM Rest API response

I'm trying to deserialize the below response to a strongly typed object using C# NewtonSoft.Json library. The issue is how to deserialize the last part

"urn:scim:schemas:extension:enterprise:1.0": {"department": "Headquarters"}

into an object.

{
"schemas": [
"urn:scim:schemas:core:1.0",
"urn:scim:schemas:extension:enterprise:1.0"
],
"userName": "ihabs@olympic.qa",
"name": {
"formatted": "Ihab Mahmoud"
},
"active": true,
"emails": [
{
"primary": true,
"type": "work",
"value": "ihabs@olympic.qa"
}
],
"addresses": [
{
"type": "work",
"formatted": "QOC Headquarter",
"primary": true
}
],
"urn:scim:schemas:extension:enterprise:1.0": {
"department": "Headquarters"
}
}


My Strongle Type Classes are

public class WPClass
{
public List<string> Schemas { get; set; }
public string Username { get; set; }
public NameNode Name { get; set; }
public bool Active { get; set; }
public List<EmailNode> Emails { get; set; }
public List<AddressNode> Addresses { get; set; }
}


The class for Address node

public class AddressNode
{
public string Type { get; set; }
public string formatted { get; set; }
public bool Primary { get; set; }

}


the class for Email Node

public class EmailNode
{
public bool Primary { get; set; }
public string Type { get; set; }
public string Value { get; set; }

}


the class for Name node

public class NameNode
{
public string formatted { get; set; }
}

Answer Source

Well, you should only create a property, and use a JsonProperty attribute :

[JsonProperty(PropertyName = "urn:scim:schemas:extension:enterprise:1.0")]
public YourEnterpriseType Enterprise { get; set; }

Not sure on the Enterprise name though.

The documentation about that.