TMS XData Json response with Proxy

Hi. I'd to know if are there any way to replace a json part while using Proxy class.
Because I'm migrating my API to XData and already existing anothers clients using JSON like the example number 2.
This is an example of my XData json.

Ex: XData return.
{
"$id": 1,
"DataOperacao": "2023-07-17T16:36:51.562",
"OperadorRegistro": 1,
"Codigo": 10014,
"Imagem": null,
"TipoProduto": 0,
"Bonificado": false,
"Produto@xdata.ref": "Produto(2)"
}

Ex: Expected return.
{
"$id": 1,
"DataOperacao": "2023-07-17T16:36:51.562",
"OperadorRegistro": 1,
"Codigo": 10014,
"Imagem": null,
"TipoProduto": 0,
"Bonificado": false,
"Produto:" {"Codigo": 2}
}

My entity is declared like this:

TAdicional = class
private
	[Column('codigo', [TColumnProp.Required])]
	FCodigo: Int64;

	[Association([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAllButRemove)]
	[JoinColumn('produto', [TColumnProp.Required], 'codigo')]
	FProduto: Proxy<TProduto>;

	[Column('imagem', [])]
	FImagem: Nullable<Integer>;

	[Column('tipo_produto', [TColumnProp.Required])]
	FTipoProduto: Integer;

	[Column('bonificado', [TColumnProp.Required])]
	FBonificado: Boolean;

	function GetProduto: TProduto;
	procedure SetProduto(const Value: TProduto);
public
	property Codigo: Int64 read FCodigo write FCodigo;
	property DataOperacao;
	property OperadorRegistro;
	property Produto: TProduto read GetProduto write SetProduto;
	property Imagem: Nullable<Integer> read FImagem write FImagem;
	property TipoProduto: Integer read FTipoProduto write FTipoProduto;
	property Bonificado: Boolean read FBonificado write FBonificado;
end;

Users can add the expand filter option to get what they want:

?$expand=Product

Other than this, you can simply create your own service operation and return the object the way you want. You can create a DTO class that doesn't use a proxy. Or, you can force the loading of the proxy in advance, as described here:

I got it. Following you tip I found a XDataServer property DefaultExpandLevel, that work's like a charm.

Thank you so much.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.