Search in sources :

Example 76 with XStream

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}&amp;pw={startPage?}&amp;format=atom\" />" + "<Url type=\"application/json\"  template=\"http://localhost:3000/products?q={searchTerms}&amp;pw={startPage?}&amp;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")));
}
Also used : XStream(com.thoughtworks.xstream.XStream) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 77 with XStream

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;
}
Also used : XStream(com.thoughtworks.xstream.XStream)

Example 78 with XStream

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);
}
Also used : HashMap(java.util.HashMap) XStream(com.thoughtworks.xstream.XStream) KpiVO(com.netsteadfast.greenstep.vo.KpiVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 79 with XStream

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;
}
Also used : XStream(com.thoughtworks.xstream.XStream)

Example 80 with 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);
}
Also used : DefaultTypeNameExtractor(br.com.caelum.vraptor.interceptor.DefaultTypeNameExtractor) XStream(com.thoughtworks.xstream.XStream) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

XStream (com.thoughtworks.xstream.XStream)199 Test (org.junit.Test)55 IOException (java.io.IOException)33 InputStream (java.io.InputStream)29 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)22 Metacard (ddf.catalog.data.Metacard)21 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)17 HashMap (java.util.HashMap)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 StaxDriver (com.thoughtworks.xstream.io.xml.StaxDriver)12 XStreamUtils.createTrustingXStream (org.kie.soup.commons.xstream.XStreamUtils.createTrustingXStream)12 Matchers.anyString (org.mockito.Matchers.anyString)11 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)10 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)10 FileNotFoundException (java.io.FileNotFoundException)9 Writer (java.io.Writer)8 ArrayList (java.util.ArrayList)8 GmlGeometryConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter)8 XStreamException (com.thoughtworks.xstream.XStreamException)7 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)7