Refine search
/** * Returns a list of any plugins that are persisted in the installing list */ @SuppressWarnings("unchecked") public static synchronized @CheckForNull Map<String,String> getPersistedInstallStatus() { File installingPluginsFile = getInstallingPluginsFile(); if(installingPluginsFile == null || !installingPluginsFile.exists()) { return null; } return (Map<String,String>)new XStream().fromXML(installingPluginsFile); }
map.put("island","faranga"); XStream magicApi = new XStream(); magicApi.registerConverter(new MapEntryConverter()); magicApi.alias("root", Map.class); String xml = magicApi.toXML(map); System.out.println("Result of tweaked XStream toXml()"); System.out.println(xml); Map<String, String> extractedMap = (Map<String, String>) magicApi.fromXML(xml); assert extractedMap.get("name").equals("chris"); assert extractedMap.get("island").equals("faranga");
/** * Reads configuration from given file and delete the file after. * * @param fileName File name. * @return Readed configuration. * @throws IOException If failed. * @see #storeToFile(IgniteConfiguration, boolean) * @throws IgniteCheckedException On error. */ private static IgniteConfiguration readCfgFromFileAndDeleteFile(String fileName) throws IOException, IgniteCheckedException { try(BufferedReader cfgReader = new BufferedReader(new FileReader(fileName))) { IgniteConfiguration cfg = (IgniteConfiguration)new XStream().fromXML(cfgReader); if (cfg.getMarshaller() == null) { Marshaller marsh = IgniteTestResources.getMarshaller(); cfg.setMarshaller(marsh); } X.println("Configured marshaller class: " + cfg.getMarshaller().getClass().getName()); if (cfg.getDiscoverySpi() == null) { TcpDiscoverySpi disco = new TcpDiscoverySpi(); disco.setIpFinder(GridCacheAbstractFullApiSelfTest.LOCAL_IP_FINDER); cfg.setDiscoverySpi(disco); } X.println("Configured discovery: " + cfg.getDiscoverySpi().getClass().getName()); return cfg; } finally { new File(fileName).delete(); } }
public static <T> T serializeAndDeserializeWithXStream(T input) { XStream xStream = new XStream(); xStream.setMode(XStream.ID_REFERENCES); if (input != null) { xStream.processAnnotations(input.getClass()); } XStream.setupDefaultSecurity(xStream); xStream.addPermission(new AnyTypePermission()); String xmlString = xStream.toXML(input); return (T) xStream.fromXML(xmlString); }
@Test public void testEncodingDecodingWithoutMetaData() throws Exception { Applications applications = InstanceInfoGenerator.newBuilder(10, 2).withMetaData(false).build().toApplications(); XStream xstream = JsonXStream.getInstance(); String jsonDocument = xstream.toXML(applications); Applications decodedApplications = (Applications) xstream.fromXML(jsonDocument); assertThat(EurekaEntityComparators.equal(decodedApplications, applications), is(true)); }
protected <S extends Score, W extends TestScoreWrapper<S>> void assertSerializeAndDeserialize(S expectedScore, W input) { XStream xStream = new XStream(); xStream.setMode(XStream.ID_REFERENCES); xStream.processAnnotations(input.getClass()); XStream.setupDefaultSecurity(xStream); xStream.allowTypesByRegExp(new String[]{"org\\.optaplanner\\.\\w+\\.config\\..*", "org\\.optaplanner\\.persistence\\.xstream\\..*\\$Test\\w+ScoreWrapper"}); String xmlString = xStream.toXML(input); W output = (W) xStream.fromXML(xmlString); assertEquals(expectedScore, output.getScore()); String regex; if (expectedScore != null) { regex = "<([\\w\\-\\.]+)( id=\"\\d+\")?>" // Start of element + "\\s*<score( id=\"\\d+\")?>" + expectedScore.toString().replaceAll("\\[", "\\\\[").replaceAll("\\]", "\\\\]") // Score + "</score>" + "\\s*</\\1>"; // End of element } else { regex = "<([\\w\\-\\.]+)( id=\"\\d+\")?/>"; // Start and end of element } if (!xmlString.matches(regex)) { fail("Regular expression match failed.\nExpected regular expression: " + regex + "\nActual string: " + xmlString); } }
@Test public void testEncodingDecodingWithMetaData() throws Exception { Applications applications = InstanceInfoGenerator.newBuilder(10, 2).withMetaData(true).build().toApplications(); XStream xstream = JsonXStream.getInstance(); String jsonDocument = xstream.toXML(applications); Applications decodedApplications = (Applications) xstream.fromXML(jsonDocument); assertThat(EurekaEntityComparators.equal(decodedApplications, applications), is(true)); }
@Test public void testEncodingDecodingWithoutMetaData() throws Exception { Applications applications = InstanceInfoGenerator.newBuilder(10, 2).withMetaData(false).build().toApplications(); XStream xstream = XmlXStream.getInstance(); String xmlDocument = xstream.toXML(applications); Applications decodedApplications = (Applications) xstream.fromXML(xmlDocument); assertThat(EurekaEntityComparators.equal(decodedApplications, applications), is(true)); }
@Test public void testEncodingDecodingWithMetaData() throws Exception { Applications applications = InstanceInfoGenerator.newBuilder(10, 2).withMetaData(true).build().toApplications(); XStream xstream = XmlXStream.getInstance(); String xmlDocument = xstream.toXML(applications); Applications decodedApplications = (Applications) xstream.fromXML(xmlDocument); assertThat(EurekaEntityComparators.equal(decodedApplications, applications), is(true)); }
/** * {@inheritDoc} * * @see marshalsec.MarshallerBase#unmarshal(java.lang.Object) */ @Override public Object unmarshal ( String data ) throws Exception { com.thoughtworks.xstream.XStream xs = new com.thoughtworks.xstream.XStream(); return xs.fromXML(data); }