Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.jenkins.plugins.casc.impl.attributes.DescribableAttribute;
import io.jenkins.plugins.casc.model.CNode;
import io.jenkins.plugins.casc.model.Mapping;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -301,8 +302,23 @@ public CNode describe(T instance, ConfigurationContext context) throws Exception
if (a != null) {
Object value = a.getValue(instance);
if (value != null) {
Object converted = Stapler.CONVERT_UTILS.convert(value, a.getType());
if (converted instanceof Collection || p.getType().isArray() || !a.isMultiple()) {
Class<?> targetType = a.getType();
Object converted = Stapler.CONVERT_UTILS.convert(value, targetType);

if (p.getType().isArray() && converted instanceof Collection<?> col) {
Class<?> component = p.getType().getComponentType();
Object array = Array.newInstance(component, col.size());
int idx = 0;
for (Object o : col) {
Array.set(array, idx++, o);
}
args[i] = array;

} else if (Set.class.isAssignableFrom(p.getType()) && converted instanceof Collection) {
args[i] = new HashSet<>((Collection<?>) converted);
} else if (converted instanceof Collection
|| (converted != null && converted.getClass().isArray())
|| !a.isMultiple()) {
args[i] = converted;
} else if (Set.class.isAssignableFrom(p.getType())) {
args[i] = Collections.singleton(converted);
Expand Down
Loading
Loading