JSON result problem

Hi,
I’m using com.google.gson package’s JsonObject to return custom Json object results from various REST services. My problem is it works fine in development environment/cuba studio, but now I have started to build and deploy the docker modules, it doesn’t work there, I get exceptions like :


Caused by: org.springframework.remoting.RemoteAccessException: Could not access HTTP invoker remote service at [clover_FusionService]; nested exception is java.lang.IllegalArgumentException: Failed to deserialize object
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.convertHttpInvokerAccessException(HttpInvokerClientInterceptor.java:216) ~[spring-web-4.3.1.RELEASE.jar:4.3.1.RELEASE]
at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:147) ~[spring-web-4.3.1.RELEASE.jar:4.3.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.1.RELEASE.jar:4.3.1.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.1.RELEASE.jar:4.3.1.RELEASE]
at com.sun.proxy.$Proxy109.getActiveAppQuestion(Unknown Source) ~[na:na]
... 80 common frames omitted
Caused by: java.lang.IllegalArgumentException: Failed to deserialize object
at com.haulmont.cuba.core.sys.serialization.StandardSerialization.deserialize(StandardSerialization.java:71) ~[cuba-global-6.3.6.jar:6.3.6]
at com.haulmont.cuba.core.sys.serialization.SerializationSupport.deserialize(SerializationSupport.java:56) ~[cuba-global-6.3.6.jar:6.3.6]

I don’t really know how could it work differently, and how could I resolve it. I have tried to send back the result as String, but obviously that won’t set the response header content type to “application/json” which is causing problems in my javascripts as they are expecting this.
Is there a way to set the response header manually or any other working way to return the result in json format?

Thanks for your help:
Gabor

Hi,
you can return result as a String and specify the response content-type as ‘application/json’. One way to do it is to use the produces attribute of the GetMapping annotation.
See Spring documentation for details: https://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-produces

Hi Max,
thank you, I will look into this, looks interesting. For now I have changed the reslttype into a Map, and apparently that gets translated to json by some cuba magic internally, which is satisfactory now :slight_smile: