Sorry this is probably super basic. But in all my javabean examples, I’ve not seen anything beyond an “int” and “String” as javabean properties.
What if I had a Person bean, and I wanted a “nicknames” property? That would be an array of “String” objects. Is that possible? Could I use a HashMap as a javabean property as well?
I’m also not clear if javabeans are allowed to have methods beyond getters and setters. If I had a Calculator bean, could I have a method like add() or subtract()?
(The reason I’m asking is related to marshalling and unmarshalling JSON to java objects using the JAX-RS specification. I think that in standard tutorials the beans are all very simple and can use the automatic marshalling and unmarshalling without writing any adapters. I’m trying to figure out at what point the automatic conversion stops working.)
Thanks!
Properties of non-primitive or simple (String) types – no problem as long as JAXB provider would be able to serialize/deserialize them.
You can add methods to your beans, no problem. If you want to be sure that fields are used for serialization you may annotate your bean with @XmlAccessorType(XmlAccessType.FIELD)