json - Return Object Null datasnap delphi XE2 and consuming in java Android -
when not want return object , return nil on server, proxy classes generated exception not convert on tjsonnull tjsonobject .. normal? can return null or tjsonnulll?
function tservermethods.getpais(codigo: integer; var erro:string): tpais; var qry: tzquery; begin result := nil; try qry := createqueryconectado(erro); qry begin close; sql.clear; sql.add(sql_get_listpaises); sql.add(' pais_codigo = :p00 '); parambyname('p00').asinteger := codigo; open; if not isempty 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 begin erro := tratarexception(e); end; end; end;
for example query customer not exist.
this error in proxy classes
java.lang.classcastexception: com.embarcadero.javaandroid.tjsonnull cannot cast com.embarcadero.javaandroid.tjsonobject 08-15 11:55:03.759: w/system.err(28204): @ com.embarcadero.javaandroid.dsproxy$tservermethods.getpais(dsproxy.java:1773)
is 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!
Comments
Post a Comment