Refine search
private static XStream createXStream(boolean json) { final XStream xstream; if (json) { // format json xstream = new XStream(new JsonHierarchicalStreamDriver()); xstream.setMode(XStream.NO_REFERENCES); } else { // sinon format xml, utilise la dépendance XPP3 par défaut xstream = new XStream(); } for (final Map.Entry<String, Class<?>> entry : XStreamAlias.getMap().entrySet()) { xstream.alias(entry.getKey(), entry.getValue()); } final MapConverter mapConverter = new MapConverter(xstream.getMapper()) { /** {@inheritDoc} */ @SuppressWarnings("rawtypes") @Override public boolean canConvert(Class type) { return true; // Counter.requests est bien une map } }; xstream.registerLocalConverter(Counter.class, "requests", mapConverter); xstream.registerLocalConverter(Counter.class, "rootCurrentContextsByThreadId", mapConverter); return xstream; } }
public HierarchicalStreamWriter createWriter(OutputStream out) { try { // JSON spec requires UTF-8 return createWriter(new OutputStreamWriter(out, "UTF-8")); } catch (UnsupportedEncodingException e) { throw new StreamException(e); } }
public static String serialise(ProjectSlackNotificationsBean project){ XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); xstream.setMode(XStream.NO_REFERENCES); xstream.alias("projectSlacknotificationConfig", ProjectSlackNotificationsBean.class); /* For some reason, the items are coming back as "@name" and "@value" * so strip those out with a regex. */ return xstream.toXML(project); }
/** * Return an Advisory message as a JSON formatted string * @param ds * @return */ protected String marshallAdvisory(final DataStructure ds) { XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); xstream.setMode(XStream.NO_REFERENCES); xstream.aliasPackage("", "org.apache.activemq.command"); return xstream.toXML(ds); } }
XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); xstream.autodetectAnnotations(true); if ((this.config != null) && (this.config.getXstreamReferenceAction() != null)) { switch (this.config.getXstreamReferenceAction()) { case absolute_references: xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES); break; case id_references:
public static String toString(Object o) { XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); return xstream.toXML(o); } }
protected void printOutput(Object o, Class... classes) { XStream xstream = null; String format = getOutput(); if (format.equals("json")) xstream = new XStream(new JsonHierarchicalStreamDriver()); else if (format.equals("xml")) xstream = new XStream(); else System.out.println(o.toString()); if (xstream != null) { xstream.setMode(XStream.NO_REFERENCES); for (Class c : classes) { xstream.processAnnotations(c); } System.out.println(xstream.toXML(o)); } }
private static final XStream jsonXStream = new XStream(new JsonHierarchicalStreamDriver()); public static String toDebugString(Object object) { return jsonXStream.toXML(object); // ignore "toXML" name, it's going to be JSON. }
public static String toXML(Node n) { XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); xstream.alias("node", Node.class); return xstream.toXML(n); }
XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); xstream.alias("myAlias", MyClass.class); Product product = (Product)xstream.fromXML(json); System.out.println(product.getName());
final XStreamListAliasWrapper wrapper = ((XStreamListAliasWrapper) object); xsObject = wrapper.object; xs.alias(wrapper.alias + "s", wrapper.collectionClass); xs.registerConverter(wrapper.createConverter()); } else if (object instanceof GridSet) { xsObject = new XMLGridSet((GridSet) object); xs, context, ContextualConfigurationProvider.Context.REST)); String xmlText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + xs.toXML(xsObject); configureXStream( XMLConfiguration.getConfiguredXStreamWithContext( new GeoWebCacheXStream(new JsonHierarchicalStreamDriver()), context, ContextualConfigurationProvider.Context.REST));
@Before public void setup() { MockitoAnnotations.initMocks(this); this.restfulie = mock(Restfulie.class); when(restfulie.newRelationBuilder()).thenReturn(builder); Configuration config = mock(Configuration.class); when(config.getApplicationPath()).thenReturn("http://www.caelum.com.br"); xstream = new XStream(new JsonHierarchicalStreamDriver()); ReflectionConverter base = new ReflectionConverter(xstream.getMapper(), xstream.getReflectionProvider()); xstream.registerConverter(new LinkConverterJSON(base, restfulie, config)); }
public static void main(String[] args) { Players xstramAliasObject = new Players(); XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); xstream.setMode(XStream.NO_REFERENCES); xstream.aliasSystemAttribute(null, "class"); xstream.autodetectAnnotations(true); System.out.println("--- "+xstream.toXML(xstramAliasObject)); }
private final XStream xstreamOut = new XStream(new JsonHierarchicalStreamDriver() { public HierarchicalStreamWriter createWriter(Writer writer) { return new JsonWriter(writer, new char[0], "", JsonWriter.DROP_ROOT_MODE); } });
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver; ... XStream dumper = new XStream(new JsonHierarchicalStreamDriver()); System.out.println(dumper.toXML(data));
protected String getDocmentsAsString(List<News> documentsListByIndex) { if(documentsListByIndex.size()>0){ try { XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); xstream.setMode(XStream.NO_REFERENCES); xstream.alias("news", News.class); return xstream.toXML(documentsListByIndex); } catch (Exception e) { e.printStackTrace(); } } return null; }
/** * Return an Advisory message as a JSON formatted string * * @param ds the DataStructure instance that is being marshaled. * @return the JSON marshaled form of the given DataStructure instance. */ protected String marshallAdvisory(final DataStructure ds) { XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); xstream.setMode(XStream.NO_REFERENCES); xstream.aliasPackage("", "org.apache.activemq.command"); return xstream.toXML(ds); } }
XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); xstream.autodetectAnnotations(true); if ((this.config != null) && (this.config.getXstreamReferenceAction() != null)) { switch (this.config.getXstreamReferenceAction()) { case absolute_references: xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES); break; case id_references:
/** * Returns a JsonRepresentation of the layer * * @param layer * @return */ public JsonRepresentation getJsonRepresentation(TileLayer layer) { JsonRepresentation rep = null; try { XStream xs = xmlConfig.getConfiguredXStream(new XStream( new JsonHierarchicalStreamDriver())); JSONObject obj = new JSONObject(xs.toXML(layer)); rep = new JsonRepresentation(obj); } catch (JSONException jse) { jse.printStackTrace(); } return rep; }
XStream xstream = new XStream(new JsonHierarchicalStreamDriver()); String json = xstream.toXML(myobject);