First of all thanks for all people that answered my previous posts ;-)
My application was not using the corresponding .betwixt because my code
defines a SecurityManager, let's try to show what happens ...
1) This is the bean that I'm using (com.betwixt.sample.PersonBean.java).:
public class PersonBean {
private String name;
private int age;
/** Need to allow bean to be created via reflection */
public PersonBean() {}
public PersonBean(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String toString() {
return "PersonBean[name='" + name + "',age='" + age + "']";
}
2) The corresponding .betwixt file (PersonBean.betwixt) it is in the same
directory as the .java file
<?xml version='1.0' encoding='UTF-8' ?>
<info primitiveTypes='attribute'>
<hide property='age'/>
<element name='personassss'>
<addDefaults/>
</element>
</info>
3) The main class (com.betwixt.sample.WriteExampleApp)
public class WriteExampleApp {
/**
* Create an example bean and then convert it to xml.
*/
public static final void main(String [] args) throws Exception {
// System.setSecurityManager(new java.rmi.RMISecurityManager()); /**
--> Here is the little devil ;-) . If the security manager is defined the
.betwixt file is not considered ;-( */
// Start by preparing the writer
// We'll write to a string
StringWriter outputWriter = new StringWriter();
// Betwixt just writes out the bean as a fragment
// So if we want well-formed xml, we need to add the prolog
outputWriter.write("<?xml version='1.0' ?>");
// Create a BeanWriter which writes to our prepared stream
BeanWriter beanWriter = new BeanWriter(outputWriter);
// Configure betwixt
// For more details see java docs or later in the main documentation
beanWriter.getXMLIntrospector
().getConfiguration().setAttributesForPrimitives(false);
beanWriter.getBindingConfiguration().setMapIDs(false);
beanWriter.enablePrettyPrint();
// If the base element is not passed in, Betwixt will guess
// But let's write example bean as base element 'person'
// beanWriter.write("person", new PersonBean("John Smith", 21));
beanWriter.write(new PersonBean("John Smith", 21));
// Write to System.out
// (We could have used the empty constructor for BeanWriter
// but this way is more instructive)
System.out.println(outputWriter.toString());
// Betwixt writes fragments not documents so does not automatically
close
// writers or streams.
// This example will do no more writing so close the writer now.
outputWriter.close();
}
}
Question.: I need to maintain the security manager in my application, Does
someone know what do I need to put in the policy file to allow my
application to read the .betwixt file ?
Thank you very much
Marcos