In what format I should return the response from RPC Service in Laminas API Tools implementation

I plan to implement an RPC Service in API Tools environment that uses a number of entities.
Following function returns the number ($offset) of records from (starting record).

public function findCustomerOrders($customerId,$offset,$from)
return $this->entityManager->getRepository(Orders::class)->findByCustomersId($customerId,$offset,$from);
//Controller function
public function listCustomerOrdersAction()
//get customer Id
$customerId = (int)$this->params()->fromRoute('customer_id',-1);
$offset = (int)$this->params()->fromRoute('offset',-1);
$from = (int)$this->params()->fromRoute('from',-1);
$orders = $this->listCustomerOrdersService->findCustomerOrders($customerId,$offset,$from);
return $orders;

The controller function here shows the output as follows:

"0": {},
"1": {},
"2": {},
"3": {},
"4": {}

In the above code when I un-comment the var_dump statement it does show lengthy output(the browser keeps on fetching data forever).
My aim is to return the records, what should be my return type and what do I return. Or do I have to use HAL as shown in the following link
Please guide.
Thanks in advance.

For an RPC Service you have to return an instance of Laminas\ApiTools\ContentNegotiation\ViewModel.

namespace Application\Controller;

use Laminas\ApiTools\ContentNegotiation\ViewModel;
use Laminas\Mvc\Controller\AbstractActionController;

class YouController extends AbstractActionController
    public function yourAction()
        // fetch your data here
        $data = [];

        return new ViewModel([
            'payload' => $data,

The data you want to return must be named under the key payload. The payload holds the data you want to return in HAL format. You can chose any other key for simple JSON format.

The Laminas API Tools are well documented. A working example how to return the HAL format from a RPC service, you can see here.

I have used the above but I am still getting the empty record though it is in HAL format:
“_links”: []
Where could I be missing?

Did you check the values of the following variables: $customerId, $offset and $from? I suggest using a debugging tool like XDebug or a simple var_dump($customerId, $offset, $from). What is the content or even better the type of $orders? You can check that with var_dump(gettype($orders)). If $orders orders is a result collection you could check, if it contains a rowset with var_dump($order->count())
With XDebug you could easily check the type and the content with a simple stoppoint.

To keep it short: Check the values of your variables and the doctrine result.