I think it would be a good idea to have an activity to serialize an object to JSON. (Since we have one for Deserialize)
It would be very useful for many stuff, but essentially for loading different types of objects in the orchestrator queue.
For this we can use JSONConvert.SerializeObject() from Newtonsoft.Json namespace
Can’t they just use the code activity now? Nice to have…
Yeah, of course… it’s only a “nice to have”
I used the JSONConvert.SerializeObject() object to turn a Dictionary with my metadata into JSON format.
JSONConvert.SerializeObject(metadata)
Since we now are switching to the new version # 2019.10.1 I cannot use the method anymore. Because when i try to publish i get the following error Method.
The assembly compilation returned the following errors:
- ‘JsonConvert’: static types cannot be used as type arguments
So now i am a bit lost on what to do.
I dont really know what to do now. How do you serialize JSON in the new Version?
@Ben_Ten did you find out a solution for this? I just got the same error while trying to publish a library to a specified folder.
Hi,
sorry for the late answer.
I wrote a Method in Python which I could then use to serialize the variables.
import json
import os
def saveAsJson(fileExtention, participationIDs, uwy, documentProfile, creationDate, author, …):
partIDs = participationIDs.split(“,”)
uwys = uwy.split(“,”)
metadataDict = {"contentRepositoryId":"UW_DOCS_DB",
"documentTypeId":"RD8DOCS",
"documentExtension":fileExtention,
"descriptors":{
"DOCTREATYNR": partIDs,
...
"INPUTCHANNEL":inputChannel
}
}
with open(os.path.join(filepath, 'metadata.json'), 'w') as json_file:
json.dump(metadataDict, json_file)
return "Metadata File Created"
When I log message to check the data type of JsonConvert.DeserializeObject(myTextItem).GetType, it’s Newtonsoft.Json.Linq.JObject.
When I put JsonConvert.DeserializeObject(myTextItem), I faced the same error as above.
My solution is to use a CType for it: CType(JsonConvert.DeserializeObject(myTextItem), Newtonsoft.Json.Linq.JObject)
Guys, all we gotta do is not have JsonConvert as a variable in our variables pane. Jsonconvert is a static class, and it tries to get instantiated. Everything worked and i was able to use it just without declaring a jsonconvert type variable.