REST Services return View on Update/Create

Is there anyway to control the View of an object that gets returned after a Create or Update through the REST Services? My main object being returned is associated to another entity that has some very big text fields. I was surprised to see the large text fields being returned after ever UPDATE/CREATE.

What options do I have?


There are no settings or request parameters that control the view of the returned JSON object. REST API response is the serialized entity that was returned by the DataManager. We’ll discuss and probably will provide an option not to return or limit the JSON for the create/update operations ( in future releases
In your project, you can override the EntitiesControllerManager bean and modify the JSON in the createEntity and updateEntity methods.

I’ve extended EntitiesControllerManager and overridden some classes and registered it as cuba_EntitiesControllerManager in the spring configuration file. I’ve done this in the web module. I’m getting an error now though: No qualifying bean of type ‘com.haulmont.restapi.common.RestControllerUtils’ available when spring is attempting to load my cuba_EntitiesControllerManager. I’m I overriding it in the wrong module?


Things are a little bit more complicated here. Let me explain. If you take a look at the web.xml file, you’ll find that requests to the /rest URLs are served by a separate dispatcher servlet:


This servlet uses a separate Spring context. Configuration files for the REST spring context are defined by the cuba.restSpringContextConfig application property. So you may do the following:

  1. Override the controller manager class in the web module.
  2. create new rest-web-spring.xml file with the overrriden bean defintiion in the web module
  3. register the rest-web-spring.xml file in the file:
cuba.restSpringContextConfig = +com/company/resttest/rest-web-spring.xml

After that your version of the controller manager will be registered in the same spring context as other REST-releated spring beans.

In a basic API request to the /entities/ path I’m now seeing a lot of extra fields not specified in the view that I’m sending as a paramenter:

We are using 6.9.5. Any update on this? Thanks.

Hi Josh,
Next time please create a separate topic for the new problem. Can you please provide more information: how does your view looks like and what extra fields are returned in the response?

As for the initial issue (Optionally do not return entity JSON for REST API entity create and update operations · Issue #691 · cuba-platform/cuba · GitHub), it is not scheduled to any release yet.

Hi @gorbunkov,
We have similar issue with CUBA 6.10.10.
I created a RestController in web module, with injected EntitiesControllerManager :

public class MyController {
    private EntitiesControllerManager entitiesControllerManager;

And, as per above guide, I added rest-web-spring.xml with component-scan of my controller package:

<context:component-scan base-package=""/>

Then I add config to

cuba.restSpringContextConfig = +com/company/sip/rest-web-spring.xml

But still getting below error:

No qualifying bean of type 'com.haulmont.restapi.service.EntitiesControllerManager' available: expected at least 1 bean which qualifies as autowire candidate.

The problem is probably that the scan is declred in the web-spring.xml.

You should either change the package name in the web-spring.xml:

<context:component-scan base-package=""/>

Or change the package for your rest controller in the rest-web-spring.xml:

<context:component-scan base-package=""/>

Hi Max,

I just created a new test project, could you help me to check where is the problem? (135.2 KB)

As I already mentioned in the previous comment, just replace

<context:component-scan base-package=""/>

with the

<context:component-scan base-package=""/>

in the web-spring.xml file.

Thank you, yes, i forgot to change web-spring.xml…