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