REST error: Unable to convert object into response content

We are getting the following error we try to post an encounter. Kindly let us know if there is something we are not doing right.

Here is the payload:

{
"encounterType": "8d5b2be0-c2cc-11de-8d13-0010c6dffd0f",
"patient": "c6e4e026-3b49-4b64-81de-05cf8bd18594",
"encounterDatetime": "2015-06-11T11:28:20Z"
}

Here is the Error:

{
error: {
message: "Unable to convert object into response content"
code: "org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource:753"
detail: "org.openmrs.module.webservices.rest.web.response.ConversionException: patient on class org.openmrs.Encounter at org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.setProperty(BaseDelegatingResource.java:753) at org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.setConvertedProperties(BaseDelegatingResource.java:610) at org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource.create(DelegatingCrudResource.java:93) at org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController.create(MainResourceController.java:86) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.openmrs.module.web.filter.ForcePasswordChangeFilter.doFilter(ForcePasswordChangeFilter.java:65) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:76) at org.openmrs.web.filter.GZIPFilter.doFilterInternal(GZIPFilter.java:59) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:74) at org.openmrs.module.webservices.rest.web.filter.AuthorizationFilter.doFilter(AuthorizationFilter.java:108) at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:74) at org.springframework.web.filter.ShallowEtagHeaderFilter.doFilterInternal(ShallowEtagHeaderFilter.java:58) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:74) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:83) at org.openmrs.module.logmanager.web.filter.RequestProviderFilter.doFilterInternal(RequestProviderFilter.java:36) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:74) at org.openmrs.module.xforms.web.XformsFilter.doFilter(XformsFilter.java:60) at org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:74) at org.openmrs.module.web.filter.ModuleFilter.doFilter(ModuleFilter.java:58) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.openmrs.web.filter.OpenmrsFilter.doFilterInternal(OpenmrsFilter.java:111) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:109) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:109) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:109) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.NullPointerException at org.openmrs.module.muzimaregistration.web.resource.RegistrationResource.getByUniqueId(RegistrationResource.java:60) at org.openmrs.module.muzimaregistration.web.resource.RegistrationResource.getByUniqueId(RegistrationResource.java:42) at org.openmrs.module.webservices.rest.web.ConversionUtil.convert(ConversionUtil.java:229) at org.openmrs.module.webservices.rest.web.ConversionUtil.convert(ConversionUtil.java:149) at org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.setProperty(BaseDelegatingResource.java:748) ... 70 more "
}-
}

By looking at the error log and this code:

https://github.com/muzima/openmrs-module-muzimaregistration/blob/development/omod/src/main/java/org/openmrs/module/muzimaregistration/web/resource/RegistrationResource.java#L60

I can assume the method is unable to find any patient with the patientId or the assigned UUID is null, can you try posting it with a different existing patient Id also debugging it with a breakpoint there might help.

Something seems to be wrong with the patient. As I can see you are sending the patient UUID to the server. Does your Resource provide a PropertySetter for “patient” that handles the UUID? See code below as an example

    @PropertySetter(value = "patient")
    public void setPatient(Encounter instance, String patientUuid) {
        PatientService patientService = Context.getService(PatientService.class);
        Patient patient = patientService.getPatientByUuid(patientUuid);
    }

@werick,

What REST end point are you calling?

The rest endpoint that am calling is encounter

Thanks That same uuid works fine when you try posting obs. That simply means that there is something wrong.

What’s the relationship between encounter and registration? Because is trying to obtain an instance of Registration, according to the stack trace.

I did upgrade the rest web services module to the latest version(2.9.39bd19) and that has solved the problem. Thanks

1 Like

I am encountering the same problem. I am using OpenMRS 1.9.7 and have installed REST web services version 2.9.39bd19 and still get the same problem. I am trying to post an Obs record into my database. The payload is as follows:

{"obs": [{"person":"00063650-ab5b-102d-be97-85aedb3d9f67", "obsDatetime": "2015-03-04", "concept": "e7c3fc94-38fa-4878-bbca-8649810008a1", "value": "38550"}]}

Any help will be appreciated!

The full error is below:

{"error":{"message":"Unable to convert object into response content","code":"org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource:740","detail":"org.openmrs.module.webservices.rest.web.response.ConversionException: obs\r\n\tat org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.getProperty(BaseDelegatingResource.java:740)\r\n\tat org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.setConvertedProperties(BaseDelegatingResource.java:654)\r\n\tat org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource.create(DelegatingCrudResource.java:93)\r\n\tat org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceController.create(MainResourceController.java:86)\r\n\tat sun.reflect.GeneratedMethodAccessor486.invoke(Unknown Source)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)\r\n\tat java.lang.reflect.Method.invoke(Unknown Source)\r\n\tat org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)\r\n\tat org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)\r\n\tat org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)\r\n\tat org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)\r\n\tat org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)\r\n\tat org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:647)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:728)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)\r\n\tat org.openmrs.module.web.filter.ForcePasswordChangeFilter.doFilter(ForcePasswordChangeFilter.java:65)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)\r\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:76)\r\n\tat org.openmrs.web.filter.GZIPFilter.doFilterInternal(GZIPFilter.java:59)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)\r\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:74)\r\n\tat org.openmrs.module.webservices.rest.web.filter.AuthorizationFilter.doFilter(AuthorizationFilter.java:108)\r\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:74)\r\n\tat org.springframework.web.filter.ShallowEtagHeaderFilter.doFilterInternal(ShallowEtagHeaderFilter.java:58)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)\r\n\tat org.openmrs.module.web.filter.ModuleFilterChain.doFilter(ModuleFilterChain.java:74)\r\n\tat org.openmrs.module.web.filter.ModuleFilter.doFilter(ModuleFilter.java:58)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)\r\n\tat org.openmrs.web.filter.OpenmrsFilter.doFilterInternal(OpenmrsFilter.java:111)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)\r\n\tat org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)\r\n\tat org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:109)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)\r\n\tat org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:109)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)\r\n\tat org.openmrs.web.filter.StartupFilter.doFilter(StartupFilter.java:109)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)\r\n\tat org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)\r\n\tat org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)\r\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)\r\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)\r\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)\r\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)\r\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)\r\n\tat org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)\r\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)\r\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)\r\n\tat org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)\r\n\tat org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)\r\n\tat org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\r\n\tat java.lang.Thread.run(Unknown Source)\r\nCaused by: java.lang.NoSuchMethodException: Unknown property 'obs'\r\n\tat org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1122)\r\n\tat org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:686)\r\n\tat org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715)\r\n\tat org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:290)\r\n\tat org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource.getProperty(BaseDelegatingResource.java:734)\r\n\t... 67 more\r\n"}}

At a glance I would guess that you should be doing:

"value": 38550

as a number, rather than as a string.

The error says Unknown property ‘obs’ … but obs is not a property of the Obs entity. Also, you’re passing an array of obs tuples to this property.

The JSON should be something like this:

{"person":"00063650-ab5b-102d-be97-85aedb3d9f67", 
"obsDatetime": "2015-03-04", "concept": 
"e7c3fc94-38fa-4878-bbca-8649810008a1", "value": "38550"}
1 Like