in xstream/src/java/com/thoughtworks/xstream/converters/extended/NamedMapConverter.java [191:231]
public NamedMapConverter(
@SuppressWarnings("rawtypes") final Class<? extends Map> type, final Mapper mapper, final String entryName,
final String keyName, final Class<?> keyType, final String valueName, final Class<?> valueType,
final boolean keyAsAttribute, final boolean valueAsAttribute, final ConverterLookup lookup) {
super(mapper, type);
this.entryName = entryName != null && entryName.length() == 0 ? null : entryName;
this.keyName = keyName != null && keyName.length() == 0 ? null : keyName;
this.keyType = keyType;
this.valueName = valueName != null && valueName.length() == 0 ? null : valueName;
this.valueType = valueType;
this.keyAsAttribute = keyAsAttribute;
this.valueAsAttribute = valueAsAttribute;
this.lookup = lookup;
enumMapper = UseAttributeForEnumMapper.createEnumMapper(mapper);
if (keyType == null || valueType == null) {
throw new IllegalArgumentException("Class types of key and value are mandatory");
}
if (entryName == null) {
if (keyAsAttribute || valueAsAttribute) {
throw new IllegalArgumentException(
"Cannot write attributes to map entry, if map entry must be omitted");
}
if (valueName == null) {
throw new IllegalArgumentException("Cannot write value as text of entry, if entry must be omitted");
}
}
if (keyName == null) {
throw new IllegalArgumentException("Cannot write key without name");
}
if (valueName == null) {
if (valueAsAttribute) {
throw new IllegalArgumentException("Cannot write value as attribute without name");
} else if (!keyAsAttribute) {
throw new IllegalArgumentException("Cannot write value as text of entry, if key is also child element");
}
}
if (keyAsAttribute && valueAsAttribute && keyName.equals(valueName)) {
throw new IllegalArgumentException("Cannot write key and value with same attribute name");
}
}