2012-08-29 4 views
2

JAXB를 클라이언트 측에서 비 정렬 화하려고 시도했지만 객체의 속성이 NULL입니다.RestFul 서비스 (spring3) 클라이언트 Java?

내가

URL url = new URL("http://localhost:9191/service/firstName/tony?format=xml"); 

    HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 

    conn.setRequestMethod("GET"); 
    conn.setRequestProperty("Accept", "application/atom+xml"); 

    if (conn.getResponseCode() != 200) { 
     throw new RuntimeException("Failed : HTTP error code : " 
       + conn.getResponseCode()); 
    } 

    BufferedReader br = new BufferedReader(new InputStreamReader(
     (conn.getInputStream()))); 


    JAXBContext jaxbContext = JAXBContext.newInstance(LDAPUsers.class); 
    Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); 


    LDAPUsers lu = (LDAPUsers) jaxbUnmarshaller.unmarshal(br); 
    ArrayList<LDAPUser> list = new ArrayList<LDAPUser>(); 


    //list.addAll(lu.getCounty()); 
    **System.out.println(lu.ldapUser.get(0).getFirstName());//this is giving NULL** 

    conn.disconnect(); 

Pls는 도움말을 비 정렬 화하기 위해 뭐하는 거지 그게 전부! 클래스가 제대로 직렬화 및 @XmlRootElement@XmlElement의 주석을 붙일 수

+0

디버그 및 목록에 브레이크 포인트를 사용하여이 문제를 디버깅에 도움이 될 수 있습니다 모든 속성이 설정되었습니다. – jmventar

+0

그것은 setter를 치지 않습니다 ... – user1534466

+0

XML과 도메인 객체는 어떻게 생겼습니까? –

답변

0

확인합니다.

this example과이 other one을 확인하십시오. 또 다른 full example.

null이 아닌 개체 및 목록이 비어 있지 않음을 확인하려면을 입력하십시오.

@RequestMapping(method=RequestMethod.GET, value="/myurl") 
public ModelAndView getUsers(@RequestBody List<LDAPUsers> users) { 
+0

해당 코드를 클라이언트 측에서 사용합니까? – user1534466

0

당신은 설정할 수 있습니다 : 마지막으로

당신이 봄 3를 사용하는 경우 당신이 연결을 관리하는 입력 스트림 이유를 이해하지 않습니다 ... 컨트롤러를 사용하여 접근을 시도, 어쩌면 당신은 사용자 정의 Unmarshaller에 필요 비 정렬 프로세스 중 _ 생한. 제 점이 _ 생한 것으 N UnmarshallerValidationEventhandler의 인스턴스가 통지되어야합니다. 이 목록이 비어와 객체 아니라는 것을 확인

jaxbUnmarshaller.setEventHandler(new ValidationEventHandler() { 

     @Override 
     public boolean handleEvent(ValidationEvent event) { 
      System.out.println(event.getMessage()); 
      return true; 
     } 

    }); 

클라이언트 예

관련 문제