Version 1.1 by eMagiz on 2022/05/22 21:29

Show last authors
1 {{html wiki="true"}}
2 <div class="ez-academy">
3 <div class="ez-academy_body">
4
5 <div class="doc">
6
7
8
9 = Transformation * JSON to XML =
10
11 In this microlearning, we will focus on transforming JSON to XML within the tooling of eMagiz. With the help of this microlearning, you will know how to transform from JSON to XML with the help of the tooling in Design and Create. To illustrate the functionality we define what needs to be done in various phases of eMagiz.
12
13 Should you have any questions, please contact academy@emagiz.com.
14
15 * Last update: April 8th, 2021
16 * Required reading time: 7 minutes
17
18 == 1. Prerequisites ==
19
20 * Basic knowledge of the eMagiz platform
21
22 == 2. Key concepts ==
23
24 This microlearning centers around transforming JSON to XML
25 By transforming we mean: Making sure that the input message is transformed in a valid output message by defining how this should happen
26
27 eMagiz natively supports the transformation of JSON to XML with the help of:
28
29 * Default message format
30 * Data models in Design
31 * Message mapping in Design
32 * Create transformation in Create
33 * Support Objects
34
35
36
37 == 3. Transformation * JSON to XML ==
38
39 In this microlearning, we will focus on transforming JSON to XML within the tooling of eMagiz. With the help of this microlearning, you will know how to transform from JSON to XML with the help of the tooling in Design and Create. To illustrate the functionality we define what needs to be done in various phases of eMagiz.
40
41 eMagiz natively supports the transformation of JSON to XML with the help of:
42
43 * Default message format
44 * Data models in Design
45 * Message mapping in Design
46 * Create transformation in Create
47 * Support Objects
48
49 === 3.1 Default message format ===
50
51 In the Design phase of eMagiz, you have the option on the system level to define the message format. In case a system speaks JSON you should set the value to JSON. If the system speaks XML you should set the value to XML.
52
53 <p align="center">[[image:novice-create-your-transformations-json-to-xml--default-message-format.png||]]</p>
54
55 Setting this up correctly will help you tremendously in the Create phase.
56
57 === 3.2 Data models in Design ===
58
59 Just as you are used to you simply create the correct system definition in Design as you would do when you would create a data model for XML message. If you are unsure how to do this please revisit the section on Design in the Crash Course Platform.
60
61 One extra thing to take into account when handling JSON is the root entity. Contrary to XML it is not mandatory to name your root entity when handling JSON. This means that when you create your data model you should verify beforehand whether the system to which you want to send your messages has a named root entity or not.
62
63 An example of a JSON message where the root entity is not named is shown below as the first example. The second example you see below is an example of a JSON message where the root entity is named.
64
65 {
66 {"ID": 1234}
67 }
68
69 {"Root":
70 {"ID": 1234}
71 }
72
73 If you need to send a name along with the JSON root in your output message you should create an extra entity in your data model with which your system message definition will start.
74
75 <p align="center">[[image:novice-create-your-transformations-json-to-xml--system-message-named-root.png||]]</p>
76
77 Regardless of whether the root of your output JSON message is named you also don't need to forget to define your message format. This can be done on the system level (in case all communication happens in JSON) or it can happen on the system message level. On the system message level, you have a button called Change message format which you can press while being in "Start Editing Mode". This action will show a pop-up. Here you can switch between XML and JSON as the message format. Ensure that the message format is JSON
78
79 <p align="center">[[image:novice-create-your-transformations-json-to-xml--change-message-format.png||]]</p>
80
81 === 3.3 Message mapping in Design ===
82
83 Just as you are used to you simply create the correct message mapping in Design as you would do when you would create a message mapping for XML messages. If you are unsure how to do this please revisit the section on Design in the Crash Course Platform.
84
85 === 3.4 Create transformation in Create ===
86
87 Just as you are used to you simply create the correct transformation functionality (filter, transformation, static input, etc.) as you would do when you would create the correct transformation functionality for XML messages. If you are unsure how to do this please revisit the section on Create in the Crash Course Platform.
88
89 === 3.5 Needed support objects ===
90
91 However, eMagiz needs to be told whether the input and/or output message is JSON. To tell this to the flow component you will need some support objects. If you have defined your default message format correctly (i.e. set it to JSON) eMagiz will auto-generate the relevant support objects for you.
92
93 Whether or not eMagiz has auto-generated the components the remainder of this section is interesting to take knowledge of. The crucial part of this is the virtual root. Remember we told you to create an extra entity in Design in your system message when the root of the JSON had a name? This is the reason why. As JSON can in theory have multiple roots which XML cannot have, yet we use the same underlying technology in eMagiz to transform both of them (JSON to JSON, JSON to XML, XML to JSON, XML to XML) you need to take this into account.
94
95 In this case, we want to transform from JSON to XML and therefore you need a JSON source factory within your flow. In this component, you need to define your virtual root based on your system message in Design. This is always the name of the root entity as defined as your system message in Design. In the example shown above, this will mean that the virtual root for this example is root.
96
97 <p align="center">[[image:novice-create-your-transformations-json-to-xml--json-source-factory.png||]]</p>
98
99 The JSON source factory is needed for your validation. However, to also support the transformation from JSON to XML you need an additional support object called Result to string transformer
100
101 <p align="center">[[image:novice-create-your-transformations-json-to-xml--result-to-string-transformer.png||]]</p>
102
103 Don't forget to properly link the support objects to the correct flow components for them to work. In the onramp, you need to link the JSON source factory to the validation component, and both support objects to the transformation.
104
105 After having done this you can use the unit testing functionality of eMagiz to test your work. If you are unsure how this functionality works please take a look at the segment on unit testing in the Crash Course Platform.
106
107 ===== Practice =====
108
109 == 4. Assignment ==
110
111 Create a transformation between JSON and XML. Ensure that you have a working solution by running a unit test.
112 This assignment can be completed with the help of the (Academy) project that you have created/used in the previous assignment.
113
114 == 5. Key takeaways ==
115
116 * eMagiz natively supports the transformation of JSON to XML with the help of:
117 * Default message format
118 * Data models in Design
119 * Message mapping in Design
120 * Create transformation in Create
121 * Support Objects
122 * Ensure that you link the support objects correctly
123 * Don't forget to define the message format
124
125
126
127 == 6. Suggested Additional Readings ==
128
129 If you are interested in this topic and want more information on it please read the help text provided by eMagiz.
130
131 == 7. Silent demonstration video ==
132
133 This video demonstrates how you could have handled the assignment and gives you some context on what you have just learned.
134
135 <iframe width="1280" height="720" src="../../vid/microlearning/novice-create-your-transformations-json-to-xml.mp4" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
136
137 </div>
138
139 </div>
140 </div>
141
142 {{/html}}