We need to support XML and JSON output from a objects, I have a List which i display in json and xml format, the problem i am facing is it also shows the underlying class, below i am showing all part of codes starting with
output
domain objects
configuration &
controller
**XML Output**
"<**com.bookstore.Books**> Unwanted
<books>
<com.bookstore.Book>
<name>book0</name>
</com.bookstore.Book>
<com.bookstore.Book>
<name>book1</name>
</com.bookstore.Book>
</books>
</com.bookstore.Books>"
**JSON Output** Unwanted part is in bold
**"org.springframework.validation.BindingResult.books**"
:[{"isbn":"03601","authors":[{"autho
I have defind book class as
@XStreamAlias("book")
public class Book {....}
and Books
@XStreamAlias("books")
public class Books {...
List<Book> books;
www.un.org/spanish/ecosoc 这些背景与本《一样。
<beans:bean id="xmlView"
class="org.springframework.web.servlet.view.xml.MarshallingView">
<beans:constructor-arg>
<beans:bean class="org.springframework.oxm.xstream.XStreamMarshaller">
<beans:property name="autodetectAnnotations" value="true"/>
</beans:bean>
</beans:constructor-arg>
</beans:bean>
<beans:bean id="jsonView"
class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
</beans:bean>
<beans:bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
</beans:bean>
www.un.org/spanish/ecosoc 控制器部分为:
@RequestMapping(value = "/books/xml")
public ModelAndView getAllBooksXML() {
List<Book> books = bookService.getAllBooks();
ModelAndView mav =
new ModelAndView("xmlView", BindingResult.MODEL_KEY_PREFIX + "books", books);
return mav;
}
@RequestMapping(value = "/books/json")
public ModelAndView getAllBooksJson() {
List<Book> books = bookService.getAllBooks();
ModelAndView mav =
new ModelAndView("jsonView", BindingResult.MODEL_KEY_PREFIX + "books", books);
return mav;
}
Please let me know otherwie i will have t
i 撰写习俗转换器。