Refine search
public synchronized void init() throws Exception { if (hierarchicalStreamDriver == null) { this.hierarchicalStreamDriver = new JettisonMappedXmlDriver(); } if (reflectionProvider == null) { xstream = new XStream(hierarchicalStreamDriver); } else { xstream = new XStream(reflectionProvider, hierarchicalStreamDriver); } }
public HierarchicalStreamWriter createWriter(final Writer writer) { try { if (useSerializeAsArray) { return new JettisonStaxWriter(new QNameMap(), mof.createXMLStreamWriter(writer), getNameCoder(), convention); } else { return new StaxWriter(new QNameMap(), mof.createXMLStreamWriter(writer), getNameCoder()); } } catch (final XMLStreamException e) { throw new StreamException(e); } }
CreateRequisitionRO product = new CreateRequisitionRO(); XStream xstream = new XStream(new JettisonMappedXmlDriver()); xstream.setMode(XStream.NO_REFERENCES); xstream.alias("product", Product.class); System.out.println(xstream.toXML(product));
@Test public void testDefaultCallback() throws Exception { MockHttpServletResponse response = getAsServletResponse(RestBaseController.ROOT_PATH + "/about/monitoring"); assertEquals(200, response.getStatus()); assertEquals("application/json", response.getContentType()); XStream xs = new XStream(new JettisonMappedXmlDriver()); xs.setMode(XStream.NO_REFERENCES); xs.alias("metric", MetricValue.class); xs.alias("metrics", Metrics.class); xs.addImplicitCollection(Metrics.class, "metrics"); Metrics metrics = (Metrics) xs.fromXML(response.getContentAsString()); assertTrue(metrics.getMetrics().size() >= MetricInfo.values().length); }
/** * Creates from the given xml string a json string. * * @param xmlString * the xml as string object * @param aliases * the aliases * @return the json string. */ public static String toJson(final String xmlString, final Map<String, Class<?>> aliases) { final Object object = XmlToObjectExtensions.toObjectWithXStream(xmlString); final XStream xstream = new XStream(new JettisonMappedXmlDriver()); if (aliases != null) { for (final Map.Entry<String, Class<?>> alias : aliases.entrySet()) { xstream.alias(alias.getKey(), alias.getValue()); } } final String json = xstream.toXML(object); return json; }
private static <K, V> XStream xStream(Map<K, V> map, List jsonConverters) { try { final XStream xstream = new XStream(new JettisonMappedXmlDriver()); xstream.setMode(XStream.NO_REFERENCES); xstream.alias("cmap", map.getClass()); registerChronicleMapConverter(map, xstream); xstream.registerConverter(new ByteBufferConverter()); xstream.registerConverter(new ValueConverter()); xstream.registerConverter(new StringBuilderConverter()); xstream.registerConverter(new CharSequenceConverter()); for (Object c : jsonConverters) { if (c instanceof Converter) { xstream.registerConverter((Converter) c); } else { LOG.warn("Skipping Converter of type class=" + c.getClass().getName() + " as " + " expecting an object of type com.thoughtworks.xstream.converters" + ".Converter"); } } return xstream; } catch (NoClassDefFoundError e) { throw new RuntimeException(logErrorSuggestXStreem, e); } }
xstream = new XStream(isJson ? new JettisonMappedXmlDriver() : new XppDriver()) { xstream = isJson ? new XStream(new JettisonMappedXmlDriver()) : new XStream();
String json = "{\"product\":{\"name\":\"Banana\",\"id\":\"123\"" + ",\"price\":\"23.0\"}}"; XStream xstream = new XStream(new JettisonMappedXmlDriver()); xstream.alias("product", Product.class); Product product = (Product)xstream.fromXML(json); System.out.println(product.getName());
InputStream is) throws RestletException, IOException { XStream xs = xmlConfig.getConfiguredXStream(new XStream(new DomDriver())); newLayer = (TileLayer) xs.fromXML(is); } else if (formatExtension.equalsIgnoreCase("json")) { HierarchicalStreamDriver driver = new JettisonMappedXmlDriver(); HierarchicalStreamReader hsr = driver.createReader(is); new HierarchicalStreamCopier().copy(hsr, new PrettyPrintWriter(writer)); writer.close(); newLayer = (TileLayer) xs.fromXML(writer.toString()); } else { throw new RestletException("Unknown or missing format extension: "
public JsonToObject(Class<T> rootClass) { xstream = new XStream(new JettisonMappedXmlDriver()); xstream.setMode(XStream.NO_REFERENCES); xstream.processAnnotations(rootClass); }
A a = new A(); // setting some values to your apple here... . . . // finally XStream xstream; xstream = new XStream(new JettisonMappedXmlDriver()); xstream.setMode(XStream.NO_REFERENCES); A.setXstreamAlias(xstream); String output = xstream.toXML(a) ;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver; // crap here XStream xstream = new XStream(new JettisonMappedXmlDriver()); xstream.alias("product", Product.class); Product product = (Product)xstream.fromXML(json);
XStream xstream = new XStream(new JettisonMappedXmlDriver()); String json = xstream.toXML(person);
protected XStream getXStream() throws Exception { XStream xstream; if (format.equals("json")) { xstream = new XStream(new JettisonMappedXmlDriver()) { protected MapperWrapper wrapMapper(MapperWrapper next) { return new MapperWrapper(next) { xstream.processAnnotations(SayHelloResponse.class); xstream.processAnnotations(ApplicationGetSourceUrlResponse.class); xstream.processAnnotations(ApplicationDeleteResponse.class); xstream.processAnnotations(ApplicationDeployResponse.class); xstream.processAnnotations(ApplicationDeployArchiveResponse.class);
protected String marshallAdvisory(final DataStructure ds, String transformation) { StringWriter buffer = new StringWriter(); HierarchicalStreamWriter out; if (transformation.toLowerCase(Locale.ENGLISH).endsWith("json")) { out = new JettisonMappedXmlDriver().createWriter(buffer); } else { out = new PrettyPrintWriter(buffer); } XStream xstream = getXStream(); xstream.setMode(XStream.NO_REFERENCES); xstream.aliasPackage("", "org.apache.activemq.command"); xstream.marshal(ds, out); return buffer.toString(); }
protected XStream getXStream() throws Exception { XStream xstream; if (format.equals("json")) { xstream = new XStream(new JettisonMappedXmlDriver()) { protected MapperWrapper wrapMapper(MapperWrapper next) { return new MapperWrapper(next) { xstream.processAnnotations(ErrorResponse.class); xstream.processAnnotations(AccountKeysResponse.class); xstream.processAnnotations(AccountInfo.class); xstream.processAnnotations(AccountListResponse.class);
/** * Marshal the Object to a string using XML or JSON encoding * * @param object the object to marshal * @param transformation the transformation to apply to the object. * @throws JMSException if an error occurs during the marshal operation. * @returns the marshaled form of the given object, in JSON or XML. */ protected String marshall(Serializable object, String transformation) throws JMSException { StringWriter buffer = new StringWriter(); HierarchicalStreamWriter out; if (transformation.toLowerCase(Locale.ENGLISH).endsWith("json")) { out = new JettisonMappedXmlDriver(new Configuration(), false).createWriter(buffer); } else { out = new PrettyPrintWriter(buffer); } getXStream().marshal(object, out); return buffer.toString(); }
XStream xstream = new XStream(new JettisonMappedXmlDriver()); xstream.setMode(XStream.NO_REFERENCES); String jsonRepresentation = map.toXML();
/** * @return * @throws IOException */ @Bean(name=OPEN_FIGI_XSTREAM_MARSHALLER) public XStreamMarshaller getXStreamMarshaller () throws IOException { XStreamMarshaller result = new XStreamMarshaller (); result.setMarshallingStrategy(new CustomMarshallingStrategy ()); result.setStreamDriver(new JettisonMappedXmlDriver()); result.setAnnotatedClasses( Data.class, MappingEntry.class, RequestBody.class ); result.getXStream().autodetectAnnotations(true); result.getXStream().omitField(Data.class, VERSION); result.getXStream().omitField(MappingEntry.class, VERSION); result.getXStream().omitField(RequestBody.class, VERSION); return result; }
/** Creates an instance configured to persist JSON. */ public XStreamPersister createJSONPersister() { return buildPersister(new JettisonMappedXmlDriver()); }