I have the following xml:
<parameters>
<parameter >value1</param>
<parameter >value2</param>
</parameters>
with the following class:
@XmlRootElement
public class Parameters {
@XmlElement public String parameter;
}
How can I get warned (exception?) of the duplicate values when unmarshaling the xml to object?
You should have a schema a make a schema validation. If your schema permits duplicates then maybe you should switch from
Stringto aCollectiontype.If you don’t have a schema, you could use schemagen tool to generate it from your java classes.
You could even generate a schema at runtime, maybe cache it together with the
JaxbContextand then use it for validation.