当我不想在服务器上返回任何对象并返回 nil 时,代理类生成了一个无法在 TJSONNull TJSONObject 上转换的异常。这正常吗?我该怎么做才能返回 null 或 tjsonnulll?
function TServerMethods.GetPais(Codigo: Integer; var Erro:String): TPais;
var
qry: TZQuery;
begin
Result := nil;
try
qry := CreateQueryConectado(Erro);
with qry do
begin
Close;
SQL.Clear;
SQL.Add(SQL_GET_LISTPAISES);
SQL.Add(' WHERE pais_codigo = :P00 ');
ParamByName('P00').AsInteger := codigo;
Open;
if not IsEmpty then
begin
Result := CreatePais;
Result.Codigo := FieldByName('pais_codigo').AsInteger;
Result.Nome := FieldByName('pais_descricao').AsString;
Result.Lingua := FieldByName('pais_lingua').AsString;
Result.Moeda := FieldByName('pais_moeda').AsString;
Result.TaxaCambio := FieldByName('pais_taxacambio').AsCurrency;
Result.Locale := FieldByName('pais_locale').AsString;
end;
end;
except
on e: Exception do
begin
Erro := TratarException(e);
end;
end;
end;
例如,来自客户的查询不存在。
这是代理类中的错误
java.lang.ClassCastException: com.embarcadero.javaandroid.TJSONNull cannot be cast to com.embarcadero.javaandroid.TJSONObject
08-15 11:55:03.759: W/System.err(28204): at com.embarcadero.javaandroid.DSProxy$TServerMethods.GetPais(DSProxy.java:1773)
是代理
private DSRESTParameterMetaData[] TServerMethods_GetPais_Metadata;
private DSRESTParameterMetaData[] get_TServerMethods_GetPais_Metadata() {
if (TServerMethods_GetPais_Metadata == null) {
TServerMethods_GetPais_Metadata = new DSRESTParameterMetaData[]{
new DSRESTParameterMetaData("Codigo", DSRESTParamDirection.Input, DBXDataTypes.Int32Type, "Integer"),
new DSRESTParameterMetaData("Erro", DSRESTParamDirection.InputOutput, DBXDataTypes.WideStringType, "string"),
new DSRESTParameterMetaData("", DSRESTParamDirection.ReturnValue, DBXDataTypes.JsonValueType, "TPais"),
};
}
return TServerMethods_GetPais_Metadata;
}
/**
* @param Codigo [in] - Type on server: Integer
* @param Erro [in/out] - Type on server: string
* @return result - Type on server: TPais
*/
public static class GetPaisReturns {
public String Erro;
public TJSONObject returnValue;
}
public GetPaisReturns GetPais(int Codigo, String Erro) throws DBXException {
DSRESTCommand cmd = getConnection().CreateCommand();
cmd.setRequestType(DSHTTPRequestType.GET);
cmd.setText("TServerMethods.GetPais");
cmd.prepare(get_TServerMethods_GetPais_Metadata());
cmd.getParameter(0).getValue().SetAsInt32(Codigo);
cmd.getParameter(1).getValue().SetAsString(Erro);
getConnection().execute(cmd);
GetPaisReturns ret = new GetPaisReturns();
ret.Erro = cmd.getParameter(1).getValue().GetAsString();
ret.returnValue = (TJSONObject)cmd.getParameter(2).getValue().GetAsJSONValue();
return ret;
}
坦克!