Using Custom Objects in an iKnode Application
iKnode applications have supported native types as a return and as parameters since its inception. This obviously limited the information that could be received and returned from an iKnode application, and in the end also its functionality.
One way to solve this was to serialize the input and outputs of the application using a JSON Serializer (or an XML Serializer). This worked ok, but it poluted the iKnode application with unnecessary serialize/deserialize code, making the application code more difficult to maintain.
The full purpose of iKnode is to make it extremely simple to create services in the cloud, automating things like security configuration, performance configuration and also serialization of custom objects.
We are proud to announce that iKnode now supports custom objects as input and as output. The way it works is with automatic serialization of custom objects into JSON.
Let’s try an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
We have 3 classes in our application, one that defines the Application class CustomObjectsTest and two classes used as input and output for the application Client and FullName. As you can see, both the Client class and the FullName class have the serializable attribute. Classes used as input/output for the application need to be serializable to work.
Let’s execute the method CreateDefaultUser():
As you can see, the output is already formatted as a JSON object. If you look at the result in the JSON viewer, you’ll be able to see the full client object in a nicer way.
Now let’s try the other method, to test the FullName object as a parameter. Input the following JSON in the fullName parameter and then click execute:
1
|
|
As you can see newly created object includes the correct full name:
Now when the iKnode Application gets call, it can be easily deserialized with the Newtonsoft JSON Library:
1
|
|
And Serialized like this:
1
|
|
For this to work, you would need to share the Client and FullName object. This example includes the Client and FullName object inside of the iKnode App for demostration purposes, but I recommend you have those in an assembly that can be shared between your Mobile or Web App and the iKnode App.
Let us know what you think.