Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am having an issue at the moment with the conversion of the Json response data for the Spaces R$est API. the documentation shows the Json (see below), the problem the use of META is repeated with different properties which causes serialization issues and "enum" is a C# datatype. Anyone have a good way to get this data. I am using C# .NET Core?
{
"data": [
{
"id": "string",
"meta": {
"roles": [],
"actions": [],
"assignableRoles": {
"enum": [
"facilitator",
"consumer",
"producer",
"dataconsumer"
],
"type": "string",
"description": "The supported roles for Shared spaces.",
"dereferenced": "#/definitions/SharedSpaceRoleType"
}
},
"name": "string",
"type": "shared",
"links": {
"self": {
"href": "string"
},
"assignments": {
"href": "string"
}
},
"ownerId": "string",
"tenantId": "string",
"createdAt": "2023-01-17T22:34:54.458Z",
"createdBy": "string",
"updatedAt": "2023-01-17T22:34:54.458Z",
"description": "string"
}
],
"meta": {
"count": 0,
"personalSpace": {
"actions": [],
"resourceType": "string"
}
},
"links": {
"next": {
"href": "string"
},
"prev": {
"href": "string"
},
"self": {
"href": "string"
}
}
}
Hi Spartan27215,
Do you need to serialize other attributes than the "data" list? (I.e. "meta", "links", "prev", "self"). If this is not needed, you should simply be able to serialize just the "data" attributes.
In order to convert the JSON information for a space into a "Space.cs" object for example, you could add a specific JsonProperty (from the "Newtonsoft.Json" package) to the fields that you want to serialize in a specific way. For example, if you had such a Space.cs object class, you could define the field "Enum", and add the JsonProperty "enum". This way, the "enum" json field is converted into the "Enum" object field when you serialize, and reverse when you deserialize.
[JsonProperty("enum")]
public string Enum{ get; set; }
Kind regards,
PythonMCSJ