How configure REST service method to return full objects in JSON not just reference

Hi,
I am quit new to CUBA platform. I created app with some REST service methods. I test it with Swagger UI. The problem I have is that: the method does not return the full object I expect - it simply returns _entityName and id (even _instanceName is empty while in fact it is not):
Response I got:

[
  {
    "_entityName": "proto2$Wezly",
    "_instanceName": "",
    "id": "1c3e2fb0-659f-1b71-ee5b-e8662f1a6f1f"
  }
]

I expect it to return full object with all attributes and links as in proto2$Wezly entity REST method e.g.

[
  {
    "_entityName": "string",
    "_instanceName": "string",
    "deleteTs": "2005-14-10T13:17:42.16Z",
    "nazwaWezla": "String",
    "czyWezelCentralny": true,
    "updatedBy": "String",
    "createdBy": "String",
    "adresWezla": "String",
    "createTs": "2005-14-10T13:17:42.16Z",
    "id": "19474a3b-99b5-482e-9e77-852be9adf817",
    "federacja": {},
    "version": 42,
    "updateTs": "2005-14-10T13:17:42.16Z",
    "deletedBy": "String"
  }
]

The method declaration in interface:

public Wezly test3(String in);

and Wezly class extends StandardEntity:

public class Wezly extends StandardEntity

What am I missing here? What do I need to change to make sure full object with all attributes and links is generated as REST service methed result?

Cheers,
Norbert

Hi,
How do you load an entity in the service method? Do you use a proper View?

Hi Max,
Thank you for your interest. I tried loading with EntityManager:

   public Wezly test3(String in) {
        Wezly w;
        try (Transaction tx = persistence.createTransaction()) {
            EntityManager em = persistence.getEntityManager();
            TypedQuery<Wezly> query = em.createQuery(
                    "select w from proto2$Wezly w", Wezly.class);
            w = query.getFirstResult();
            tx.commit();
        }
        return w;
    }

But also I tried creating and returning object with constructor. Same result.

Is there a way to point to a view which is supposed to be used for JSON serialization in a service method?

Norbert

There is a “setViewName” method in the TypedQuery interface. You can use it. Another option is to use the DataManager instead of the EntityManager for loading entities.

I would like to share a solution to my problem:
The problem I experienced was caused by Anonymous user permission restrictions.

I tested the REST service using Swagger UI using anonymous access (no authentication). Anonymous user had no access to Entities.
When I added necessary permissions to Anonymous user - full structure of the entity was sent as a REST service result.

In this case I can control what appears in the result with appropriate view.

Thanks for any help!