ServiceStack Typescript客户端未加载字典



我的ServiceStack API中有一个端点,该端点返回字典作为返回对象的一部分。对象的其余部分按预期填充,但dictionary部分只是作为一个空对象返回。这是我第一次尝试使用ServiceStack类型脚本客户端,我不知道为什么会发生这种情况。使用axios访问端点如预期一样,但我们确实希望能够使用ServiceStack客户端而不是axios。

使用ServiceStack客户端的调用:

getTotals = async (financialPeriodType: any, entityId: any) => {
const client = new JsonServiceClient('apiAddress');
client.bearerToken = this.context.JWTToken;
client.credentials = 'omit';
const request = new ServiceStack.GetFinancialTotals();
request.financialPeriodType = financialPeriodType;
request.entityId = entityId;
const ret = await client.get(request);
console.log(ret.result);
return ret.result;
};

应该填充字典的DTO:

export class GetFinancialTotalsModel {
public entityId: string;
public financialPeriodType: FinancialPeriodType;
public totalCost: number;
public budgetAmount: number;
public savingsAmount: number;
public productCategoryCosts: { [index: string]: number };
public constructor(init?: Partial<GetFinancialTotalsModel>) {
(Object as any).assign(this, init);
}
}

除了作为空对象填充的productCategoryCosts之外,所有内容都得到了正确填充

TypeScript没有"反序列化步骤",即TypeScript类只为返回的内容提供静态类型信息,如果没有填充内容,则不会返回,请查看原始JSON响应以查看返回的内容。

最新更新