File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
main/kotlin/com/ctrlhub/core/datacapture/resource
test/kotlin/com/ctrlhub/core/datacapture Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -67,9 +67,17 @@ class FormSubmissionVersion @JsonCreator constructor(
6767 @JsonProperty(" resources" )
6868 var resources : List <Map <String , Any >>? = null ,
6969) {
70+ val rawPayload: String?
71+ get() = payload?.let {
72+ try {
73+ mapper.writeValueAsString(it)
74+ } catch (e: Exception ) {
75+ null
76+ }
77+ }
7078
7179 // shared Jackson mapper configured to ignore unknown properties when hydrating attribute maps
72- private fun resourceMapper (): ObjectMapper = Companion . mapper
80+ private fun resourceMapper (): ObjectMapper = mapper
7381
7482 /* *
7583 * Convert the raw resources list (List<Map<...>>) into typed JsonApiEnvelope objects.
Original file line number Diff line number Diff line change @@ -107,6 +107,14 @@ class FormSubmissionVersionsRouterTest {
107107 assertNotNull(result.payload)
108108 assertTrue(result.payload!! .containsKey(" aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" ))
109109 assertTrue(result.payload!! .containsKey(" bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb" ))
110+
111+ // check rawPayload is a valid JSON string
112+ assertNotNull(result.rawPayload)
113+ assertTrue(result.rawPayload!! .startsWith(" {" ))
114+ assertTrue(result.rawPayload!! .endsWith(" }" ))
115+ // verify it contains the expected keys in JSON format
116+ assertTrue(result.rawPayload!! .contains(" aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" ))
117+ assertTrue(result.rawPayload!! .contains(" bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb" ))
110118 }
111119 }
112120
@@ -169,6 +177,14 @@ class FormSubmissionVersionsRouterTest {
169177 assertNotNull(result.payload)
170178 assertTrue(result.payload!! .containsKey(" aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" ))
171179 assertTrue(result.payload!! .containsKey(" bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb" ))
180+
181+ // check rawPayload is a valid JSON string
182+ assertNotNull(result.rawPayload)
183+ assertTrue(result.rawPayload!! .startsWith(" {" ))
184+ assertTrue(result.rawPayload!! .endsWith(" }" ))
185+ // verify it contains the expected keys in JSON format
186+ assertTrue(result.rawPayload!! .contains(" aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" ))
187+ assertTrue(result.rawPayload!! .contains(" bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb" ))
172188 }
173189 }
174190}
You can’t perform that action at this time.
0 commit comments