Accessing a List autogenerated from XML Schema by Netbeans
-
26-04-2021 - |
Domanda
I've auto generated code in Netbeans for an XML schema document into a package named jaxb. The root element Nutrition contains a child element named food that may appear many times.
<xsd:element name="food" maxOccurs="unbounded">
The Nutrition Object created by the autogeneration contains a protected List of Food objects.
protected List<Nutrition.Food> food;
When I try to add a Food object to the List with dot notation I can't access the list to add Food objects
Nutrition nutrition = objFactory.createNutrition(); //make a Nutrition object
Food food1 = objFactory.createNutritionFood(); // make a Food object
nutrition.food.add(food1); // add a Food object
Netbeans complains that "food has protected access in jaxb.Nutrition" I can't make the List public because it's auto generated. I've looked through the auto generated code for other methods with a reference to the List and there is only a getter that returns a copy of the list. How do I access the List to add a food object?
Nessuna soluzione corretta
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow