@SuppressWarnings("unchecked") protected static List runSmooksTransform() throws IOException, SAXException, SmooksException { Smooks smooks = new Smooks(); try { // **** // And here's the configuration... configuring the CSV reader and // the direct // binding config to create a List of Person objects // (List<Person>)... // **** smooks.setReaderConfig( new CSVReaderConfigurator("firstName,lastName,gender,age,country") .setBinding(new CSVBinding("customerList", Customer.class, CSVBindingType.LIST))); // Configure the execution context to generate a report... ExecutionContext executionContext = smooks.createExecutionContext(); executionContext.setEventListener(new HtmlReportGenerator("target/report/report.html")); JavaResult javaResult = new JavaResult(); smooks.filterSource(executionContext, new StringSource(messageIn), javaResult); return (List) javaResult.getBean("customerList"); } finally { smooks.close(); } }
public void test_simple_smooks_config() throws Exception { test_config_file("simple_smooks_config"); // Programmatic config.... Smooks smooks = new Smooks(); smooks.setReaderConfig(new JSONReaderConfigurator()); test_config_file("simple_smooks_config", smooks); }
public void test_configured_different_node_names() throws Exception { test_config_file("configured_different_node_names"); // Programmatic config.... Smooks smooks = new Smooks(); smooks.setReaderConfig( new JSONReaderConfigurator().setRootName("root").setArrayElementName("e")); test_config_file("configured_different_node_names", smooks); }
public void test_key_replacement() throws Exception { test_config_file("key_replacement"); // Programmatic config.... Smooks smooks = new Smooks(); Map<String, String> keyMap = new HashMap<String, String>(); keyMap.put("some key", "someKey"); keyMap.put("some&key", "someAndKey"); smooks.setReaderConfig(new JSONReaderConfigurator().setKeyMap(keyMap)); test_config_file("key_replacement", smooks); }
public void test_several_replacements() throws Exception { test_config_file("several_replacements"); // Programmatic config.... Smooks smooks = new Smooks(); smooks.setReaderConfig( new JSONReaderConfigurator() .setKeyWhitspaceReplacement("_") .setKeyPrefixOnNumeric("n") .setIllegalElementNameCharReplacement(".") .setNullValueReplacement("##NULL##")); test_config_file("several_replacements", smooks); }