3

JAXB オブジェクトを返す XML ベースの Web サービスへの Web サービス フロントエンドを作成する必要があります。私のフロントエンドは RESTful 形式を返す必要があります。それをJSONに変換する方法はありますか?クラスパスにjackson -mapper-asljackson-core-aslがあります。

簡単なテストとして、Book の Bean を返すと、JSON として出力されますが、JAXB オブジェクト (配信スケジュール) は XML 形式のままです。

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class DSWLIClient {

    @Autowired
    private DeliveryScheduleWS wliService;
    private BookService bs;

    @RequestMapping(value = "/DSDetails/{ds-number}", method = RequestMethod.GET)
    public @ResponseBody
    DeliverySchedule getDSDetails(@PathVariable("ds-number") String dsNumber) {
        DeliveryScheduleResponse dsDetails = wliService.getDeliveryScheduleWSSoap().getDSDetails(dsNumber);
        DeliverySchedule deliverySchedule = dsDetails.getDeliverySchedule();
        return deliverySchedule;
    }


    @RequestMapping(value = "/BookDetails/{isbn-number}", method = RequestMethod.GET)
    public @ResponseBody
    Book getBookDetails(@PathVariable("isbn-number") String isbnNumber) {
        bs = new BookService();
        Book b = bs.getBookByIsbn(isbnNumber);
        System.out.println(b.getAuthor());
        return b;
    }


}
4

1 に答える 1

1

構成ファイル (XML またはクラス) を表示できますか?

また、ContentNegotiatingViewResolver ではなく、HttpMessageConverter ( http://www.ibm.com/developerworks/web/library/wa-restful/ ) クラスを使用していると仮定します。

ほとんどの場合、必要な構成「mvc:annotation-driven」を追加するのを忘れているためです。

コンテンツ ネゴシエーション ビューを使用する場合、この例はすばらしいhttp://www.mkyong.com/spring-mvc/spring-3-mvc-contentnegotiatingviewresolver-example/

于 2012-06-05T17:06:55.833 に答える