use of com.thoughtworks.xstream.XStream in project restfulie-java by caelum.
the class UrlTest method shouldConvertAnElementWithTwoUrl.
@Test
public void shouldConvertAnElementWithTwoUrl() {
String xml = "<OpenSearchDescription>" + "<Url type=\"application/atom+xml\" template=\"http://localhost:3000/products?q={searchTerms}&pw={startPage?}&format=atom\" />" + "<Url type=\"application/json\" template=\"http://localhost:3000/products?q={searchTerms}&pw={startPage?}&format=json\" />" + "</OpenSearchDescription>";
XStream stream = new XStream();
stream.processAnnotations(SearchDescription.class);
stream.processAnnotations(Url.class);
SearchDescription desc = (SearchDescription) stream.fromXML(new StringReader(xml));
assertThat(desc.getUrls().size(), is(equalTo(2)));
assertThat(desc.getUrls().get(0).getTemplate(), is(equalTo("http://localhost:3000/products?q={searchTerms}&pw={startPage?}&format=atom")));
assertThat(desc.getUrls().get(0).getType(), is(equalTo("application/atom+xml")));
assertThat(desc.getUrls().get(1).getTemplate(), is(equalTo("http://localhost:3000/products?q={searchTerms}&pw={startPage?}&format=json")));
assertThat(desc.getUrls().get(1).getType(), is(equalTo("application/json")));
}
use of com.thoughtworks.xstream.XStream in project restfulie-java by caelum.
the class XmlSerializer method getXStream.
@Override
protected XStream getXStream() {
XStream instance = super.getXStream();
instance.processAnnotations(Order.class);
instance.processAnnotations(Item.class);
return instance;
}
use of com.thoughtworks.xstream.XStream in project bamboobsc by billchen198318.
the class KpiLogicServiceImpl method findKpis.
/**
* for TEST
* 這是測試 WS REST 用的 metod , 暴露 KPIs 主檔資料
*
* rest address: http://127.0.0.1:8080/gsbsc-web/services/jaxrs/kpis/
*
* json:
* http://127.0.0.1:8080/gsbsc-web/services/jaxrs/kpis/json
*
* xml:
* http://127.0.0.1:8080/gsbsc-web/services/jaxrs/kpis/xml
*
* @param format example: xml / json
* @return
* @throws ServiceException
* @throws Exception
*/
@WebMethod
@GET
@Path("/kpis/{format}")
@Override
public String findKpis(@WebParam(name = "format") @PathParam("format") String format) throws ServiceException, Exception {
List<KpiVO> kpis = null;
try {
kpis = this.kpiService.findListVOByParams(null);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null == kpis) {
kpis = new ArrayList<KpiVO>();
}
}
if ("json".equals(format)) {
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("KPIS", kpis);
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(paramMap);
}
XStream xstream = new XStream();
//xstream.registerConverter( new DateConverter() );
xstream.setMode(XStream.NO_REFERENCES);
xstream.alias("KPIS", List.class);
xstream.alias("KPI", KpiVO.class);
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + xstream.toXML(kpis);
}
use of com.thoughtworks.xstream.XStream in project restfulie-java by caelum.
the class CustomJsonDeserializer method getXStream.
/**
* Extension point to configure your xstream instance.
* @return the configured xstream instance
*/
protected XStream getXStream() {
XStream xstream = super.getXStream();
xstream.processAnnotations(Item.class);
return xstream;
}
use of com.thoughtworks.xstream.XStream in project restfulie-java by caelum.
the class MyCollectionConverter method main.
public static void main(String[] args) {
JSONSerializationCustomized ser = new JSONSerializationCustomized(null, new DefaultTypeNameExtractor(), null);
XStream xstream = ser.getXStream();
List l = new ArrayList();
l.add(new Item("a", "b"));
l.add(new Item("d", "c"));
System.out.println(xstream.toXML(l));
List l2 = (List) xstream.fromXML(xstream.toXML(l));
System.out.println(l2);
}
Aggregations