1

When I do not want to return any object and return nil on the server, the proxy classes generated an exception that could not convert on TJSONNull TJSONObject .. is this normal? what can I do to return null or 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;

For example a query from a customer does not exist.

this a error in the proxy classes

    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)

is the proxy

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;
}

Tanks!

0 Answers0