0
EDITED得到泛型類型寧靜的響應
我有麻煩費時使用新澤西州的Java EE Web應用程序RESTful Web服務。我有一個寧靜的Web服務(用於測試目的),我必須使用響應來顯示它。問題是我在使用泛型類型的字段上獲得ElementNSImpl對象。我究竟做錯了什麼?非常感謝。
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces("application/json; charset=utf-8")
public ResultadoConsulta consultar(LiquidacionProvisoriaEntradaServicio parametro){
ResultadoConsulta<ResultadoLiquidacionDetalleRespuestaServicio> resultado = new ResultadoConsulta<>();
List<ResultadoLiquidacionDetalleRespuestaServicio> lista = new ArrayList<>();
ResultadoLiquidacionDetalleRespuestaServicio r = new ResultadoLiquidacionDetalleRespuestaServicio();
r.setCodigoConcepto(1);
r.setCodigoFormaPago("formapago");
r.setDescripcionConcepto1("descripcion 1");
r.setDescripcionConcepto2("descripcion 2");
r.setDescripcionEmpresaFacturadora("empresa facturadora");
r.setFechaComprobante(new Date());
r.setFechaGeneracionConcepto(new Date());
r.setIdEmpresaFactura(1);
r.setImporteConcepto(2F);
r.setNumeroCuenta(1234);
r.setNumeroCuentaFactura(12343);
r.setNumeroFormaPago(Short.valueOf("2"));
lista.add(r);
resultado.setListaResultado(lista);
resultado.setCantidadRegistrosTotales(200);
resultado.setNumeroPagina(1);
resultado.setTamanoPagina(1);
return resultado;
}
而且從我的客戶端的方法:
public <T> T ejecutarWebServiceJsonPost(Object requestEntity, Class<T> responseType) throws ClientErrorException {
return webTarget.request(javax.ws.rs.core.MediaType.APPLICATION_JSON).post(javax.ws.rs.client.Entity.entity(requestEntity, javax.ws.rs.core.MediaType.APPLICATION_JSON), responseType);
}
響應類:
@XmlRootElement
public class ResultadoConsulta<T> {
@XmlElement
private List<T> listaResultado;
@XmlElement
private Integer cantidadRegistrosTotales;
@XmlElement
private Integer numeroPagina;
@XmlElement
private Integer tamanoPagina;
}
嗨,卡洛斯,謝謝你的回答。我已經試過了,並沒有爲我工作...... –
你如何嘗試在你的客戶端得到響應? –
這是我的客戶的方法...... '公共牛逼ejecutarWebServiceJsonPost(對象requestEntity,類的responseType)拋出ClientErrorException { 回報webTarget.request(javax.ws.rs.core.MediaType.APPLICATION_JSON)。員額(javax.ws.rs.client.Entity.entity(requestEntity,javax.ws.rs.core.MediaType.APPLICATION_JSON),responseType); }' –