R5 JsonParser is accepting array values for valueString data type in extension

55 views
Skip to first unread message

shobha kishan

unread,
Aug 30, 2022, 4:58:47 PM8/30/22
to HAPI FHIR

Hi,
We are sending array values to "valueString" data type in Extension element like

"valueString" : ["test1" , "test2"]. FhirContext.forR5() JsonParser is not throwing any validation error as we are passing array value to scalar data type instead JsonParser is setting "valueString" element value as "test2" which is last element in the array when we construct FHIR Resource object from Json string.

Is this expected behavior? If so is there any work around to fix this issue as this issue is noticed for all data types in Extension element.

Any help would be appreciated.

Thanks,
Shobha

James Agnew

unread,
Aug 30, 2022, 5:33:17 PM8/30/22
to shobha kishan, HAPI FHIR
You should be able to configure a parser error handler to increase the strictness of this parsing. I believe by default cardinality differences are handled as a warning by the lenient error handler but you can use the strict error handler to make this an error.


Cheers,
James

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/6795a420-c544-4056-9aed-76044be59f8cn%40googlegroups.com.

shobha kishan

unread,
Aug 31, 2022, 11:05:36 AM8/31/22
to HAPI FHIR
Hi James,

Thank you for your reply. I have tested by adding StrictErrorHandler to JsonParser. But still value[x] fields cardinality is not getting validated and not throwing any exception or logging messages if we pass array value to SCALAR data type.
JsonParser is validating only primitive data types like "String" , "Boolean" etc for cardinality and throwing exception if we pass array values for these data types.

Regards,
Shobha.

James Agnew

unread,
Aug 31, 2022, 11:39:29 AM8/31/22
to shobha kishan, HAPI FHIR
Ah interesting. That sounds like it's probably a bug in that case. Please feel free to file a ticket (and of course PRs are always welcome).

You could also use ResponseValidatingInterceptor (assuming you're building a server) to catch this.

Cheers,
James

shobha kishan

unread,
Aug 31, 2022, 11:51:55 AM8/31/22
to HAPI FHIR
Ticket https://github.com/hapifhir/hapi-fhir/issues/3943  is raised for the same.
I will try to see how to use ResponseValidatingInterceptor as temporary fix until HAPI FHIR provides the fix.

Thank you for your suggestions.

Thanks,
Shobha.

shobha kishan

unread,
Aug 31, 2022, 6:50:32 PM8/31/22
to HAPI FHIR
Further debugging into the issue got to know that JsonParser will not validate extension elements cardinality while parsing. We have added custom extensions to Basic resource and added corresponding structure definitions for this custom profile. But JsonParser is not using this custom structure definitions during parsing and also extension elements cardinality also not validated.

Is there any work around other than ResponseValidatingInterceptor to validate the input request and throw this parsing errors?
Reply all
Reply to author
Forward
0 new messages