2

クライアント側で JAXB を非整列化しようとしていますが、オブジェクトのプロパティが NULL になっています。

それが私が非整列化するためにしていることです

    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 は助けて!!!

4

2 に答える 2

0

アンマーシャリング プロセス中に発生した問題が通知されるようValidationEventhandlerにのインスタンスを設定できます。Unmarshallerこれは、問題のデバッグに役立ちます。

    jaxbUnmarshaller.setEventHandler(new ValidationEventHandler() {

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

    });

クライアントの例

于 2012-08-29T11:24:13.923 に答える
0

クラスが正しくシリアル化され、@XmlRootElementおよび@XmlElementで注釈が付けられていることを確認してください。

この例とこの他の例を確認してください。別の完全な例

not nullオブジェクトとlist not emptyをチェックするアサーションをいくつか入れます。

最後に、Spring 3 を使用している場合、接続と入力ストリームを管理している理由がわかりません...コントローラーを使用したアプローチを試してください。カスタム アンマーシャラーが必要になる場合があります。

@RequestMapping(method=RequestMethod.GET, value="/myurl")
public ModelAndView getUsers(@RequestBody List<LDAPUsers> users) {
于 2012-08-29T11:15:59.597 に答える