Often the Java interface we are using will have convenience methods that appear to be additional properties but are actually just a simpler way of accessing another property. An example is shown as follows:
public class QuoteRequest implements Serializable { ... private String[] products; ... public void setProducts(String[] products) { this.products = products; } public String[] getProducts() { return products; } public String getProduct(int i) { ... } public String getProduct() { return getProduct(0); } public void setProduct(String product) { products = new String[1]; products[0] = product; return; } ... }
In this example, the getProduct
and setProduct
methods are just simplified interfaces to the getProducts
and setProducts
methods in the case where there is only one product required. We would not want to generate an XML element for both the product
and the products
properties of this bean, so in this recipe...