use of org.apache.commons.collections.map.AbstractMapDecorator in project configuration-as-code-plugin by jenkinsci.
the class ModelConstructor method constructMapping2ndStep.
/**
* Enforce Map keys are only Scalars and can be used as {@link String} keys in {@link Mapping}
*/
@Override
protected void constructMapping2ndStep(MappingNode node, final Map mapping) {
((Mapping) mapping).setSource(getSource(node));
super.constructMapping2ndStep(node, new AbstractMapDecorator(mapping) {
@Override
public Object put(Object key, Object value) {
if (!(key instanceof Scalar))
throw new IllegalStateException("We only support scalar map keys");
Object scalar = ObjectUtils.clone(value);
if (scalar instanceof Number)
scalar = new Scalar(scalar.toString());
else if (scalar instanceof Boolean)
scalar = new Scalar(scalar.toString());
return mapping.put(key.toString(), scalar);
}
});
}
Aggregations