use of org.simpleframework.xml.core.Persister in project c2mon by c2mon.
the class DeviceFacadeImpl method parseDevicePropertiesXML.
/**
* Parse the XML representation of the properties of a device (which comes
* from configuration) and return it as a list of {@link DeviceProperty}
* objects.
*
* @param xmlString the XML representation string of the device properties
*
* @return the list of device properties
* @throws Exception if the XML could not be parsed
*/
private List<DeviceProperty> parseDevicePropertiesXML(String xmlString) throws Exception {
List<DeviceProperty> deviceProperties = new ArrayList<>();
Serializer serializer = new Persister();
DevicePropertyList devicePropertyList = serializer.read(DevicePropertyList.class, xmlString);
for (DeviceProperty deviceProperty : devicePropertyList.getDeviceProperties()) {
// Remove all whitespace and control characters
if (deviceProperty.getValue() != null) {
deviceProperty.setValue(deviceProperty.getValue().replaceAll("[\u0000-\u001f]", "").trim());
}
deviceProperties.add(deviceProperty);
}
return deviceProperties;
}
use of org.simpleframework.xml.core.Persister in project java-apply by javachengwc.
the class Main method main.
public static void main(String[] args) throws Exception {
Serializer serializer = new Persister();
Main example = new Main("Example message", 123);
File result = new File("E:/tmp/example.xml");
serializer.write(example, result);
Main _obj = serializer.read(Main.class, result);
System.out.println(_obj.getMessage());
}
use of org.simpleframework.xml.core.Persister in project java-apply by javachengwc.
the class Main2 method main.
public static void main(String[] args) throws Exception {
Customer customer = new Customer(111L, "张三");
Order order1 = new Order(1L, new Date());
Order order2 = new Order(2L, new Date());
Item item11 = new Item(1, 11L);
Item item21 = new Item(2, 21L);
Address address = new Address("450000", "瑞达路XX#", true);
customer.setAddress(address);
customer.getOrderList().add(order1);
customer.getOrderList().add(order2);
order1.getItemList().add(item11);
order2.getItemList().add(item21);
Serializer serializer = new Persister();
File result = new File("E:/tmp/customer.xml");
serializer.write(customer, result);
Customer _obj = serializer.read(Customer.class, result);
System.out.println(_obj.getName());
System.out.println(_obj.getOrderList().get(0).getCdate());
}
use of org.simpleframework.xml.core.Persister in project formplayer by dimagi.
the class FormSubmissionController method parseSubmitResponseMessage.
private void parseSubmitResponseMessage(String responseBody, SubmitResponseBean submitResponseBean) {
if (responseBody != null) {
try {
Serializer serializer = new Persister();
OpenRosaResponse openRosaResponse = serializer.read(OpenRosaResponse.class, responseBody);
if (openRosaResponse != null && openRosaResponse.getMessage() != null) {
submitResponseBean.setSubmitResponseMessage(openRosaResponse.getMessage());
}
} catch (Exception e) {
log.error("Exception parsing submission response body", e);
}
}
}
use of org.simpleframework.xml.core.Persister in project syncany by syncany.
the class ConfigTO method load.
public static ConfigTO load(File file) throws ConfigException {
try {
Registry registry = new Registry();
Strategy strategy = new RegistryStrategy(registry);
registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter());
registry.bind(String.class, new EncryptedTransferSettingsConverter());
return new Persister(strategy).read(ConfigTO.class, file);
} catch (ClassNotFoundException ex) {
// Ugly hack to catch common case of non-existing plugin
String message = ex.getMessage();
if (!message.startsWith("org.syncany.plugins.")) {
// Apparently there are other ClassNotFoundExceptions possible.
throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
}
message = message.replaceFirst("org.syncany.plugins.", "");
message = message.replaceAll("\\..*", "");
throw new ConfigException("Is the " + message + " plugin installed?");
} catch (Exception ex) {
throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
}
}
Aggregations