How to convert a JSON formatted string into a Map<String, Object> ?

Hi guys,

In HtmlFormEntry the <uiInclude> tag only allows to include fragments but with no config parameters. However it could be great to be able to do it (pass the config parameters to a fragment).

Something like this:

<uiInclude provider="uicommons" fragment="field/datetimepicker" config="{ "id": "startDate",
			"formFieldName": "encounterDate",
			"useTime": false

There is already the right method available to include a fragment with config parameters:

But that is just not handled in the tag handler itself:

It looks easy enough to parse the tag to retrieve the config string and call the appropriate function but my problem is that the method includeFragment(String providerName, String fragmentId, Map<String, Object> config) requires a Map object as 3rd argument, but my “config” parameter is provided as a String.

Q: Is there an existing way in OpenMRS to convert a configuration String into a Map<String, Object> ?

My suggestion (given the context in which you’re trying to do this) is to look at what’s in the UI Framework module, e.g. in UiFrameworkUtil (maybe something like determineArgumentValue?). Hopefully Spring’s ConversionService handles this in some way.

Actually, I would presume that each “config” should be its own parameter in the tag, e.g. do not do this:

<includeFragment ... config="{length: 10}"/>

but do this:

<includeFragment ... length="10"/>

Thanks @darius for that. I’ll have a look at it and update the thread.

Thank you


were you able to figure this out?

1 Like

I tried this and it din’t work