2017-05-05 4 views
0

좋은 아침되지는 JAX-RS에서 잘 작동 할, 내가 일반적인 가지고 나머지 서비스의 답변에 문제가, 나는 다음과 같은 구조를 가지고 일반 객체가나머지 일반이

@Path("/pruebas") 
public class Pruebita { 
    @GET 
    public Data getalgo(){ 
     ObjectoDatos od=new ObjectoDatos(); 
     od.setPrueba("hola"); 
     od.setPrueba2("hola2"); 
     Data sd=new Data(); 
     sd.setData(od); 
     sd.setNumero_reg(1); 
     return sd; 
    } 
} 

을하지만 응답 JSON을 충족 할 때이 객체의 toString과이되었다 볼 수있는 대답은 다음과 같습니다 표준화 된 응답의 목적으로 다른 나머지를 충족 객체에 반대하는 나머지 하나의 대답은 다음과 개체의 데이터가 표시되지 않으면 누군가가 나를 도울 수 있습니까?

{"data":"[email protected]","numero_reg":1} 

오류입니다, 내가 문자열 객체에 도착, 나는 해결책을 발견 객체

+0

Documentos 클래스의 toString 메서드를 재정의 했습니까? 이 수업에는 무엇이 있습니까? – Nathan

+0

Documentos 클래스를 ObjectMapper에 추가 했습니까? –

+0

그렇습니다 tostring 메서드는 jpa 엔티티를 덮어 씌우고 있습니다. 그러나 Java pojo와 함께 tostring 메서드를 재정의하지 않고 시도했습니다. gen.ric에 "[email protected]"가 있습니다. – programmercito

답변

0

해달라고 : 내가 재 포장 구아바에 HashMaps을 클래스를 사용 을 :

@Override 
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { 
    int response = responseContext.getStatus(); 
    Object entidad = responseContext.getEntity(); 
    if (entidad != null && response == 200) { 
     int nroRegistros = (entidad instanceof List) ? (((List) entidad).size()) : 1; 
     Map<String, Object> respuesta = Maps.newHashMap(); 
     respuesta.put("data", entidad); 
     if(nroRegistros != 1) { 
      respuesta.put("numero_reg", nroRegistros);     
     } 
     responseContext.setEntity(respuesta); 
    } 
} 

을하고 잘 작동 .

관련 문제