@@ -169,7 +169,7 @@ public Object convert(Map<String, Object> raw, ConverterContext ctx) throws Link
169169
170170 if ( designatorSlot .isMultivalued () ) {
171171 ArrayList <String > designatorNames = new ArrayList <>();
172- for ( Object rawDesignator : toList (designator ) ) {
172+ for ( Object rawDesignator : toList (designator , true ) ) {
173173 designatorNames .add (designatorConverter .convert (rawDesignator , ctx ).toString ());
174174 }
175175 designatedClass = resolver .resolve (designatorNames , klass );
@@ -293,7 +293,7 @@ protected String getGlobalIdentifier(Object raw, ConverterContext ctx) throws Li
293293 protected List <String > getGlobalIdentifierList (Object raw , ConverterContext ctx ) throws LinkMLRuntimeException {
294294 IConverter conv = ctx .getConverter (klass .getIdentifierSlot ());
295295 ArrayList <String > list = new ArrayList <>();
296- for ( Object rawItem : toList (raw ) ) {
296+ for ( Object rawItem : toList (raw , true ) ) {
297297 list .add (conv .convert (rawItem , ctx ).toString ());
298298 }
299299 return list ;
@@ -366,7 +366,7 @@ public Map<String, Object> serialise(Object object, boolean withIdentifier, Conv
366366 public Object serialiseForSlot (Object object , Slot slot , ConverterContext ctx ) throws LinkMLRuntimeException {
367367 InliningMode inlining = slot .getInliningMode ();
368368 if ( slot .isMultivalued () ) {
369- List <Object > items = toList (object );
369+ List <Object > items = toList (object , false );
370370 if ( inlining == InliningMode .LIST ) {
371371 List <Object > list = new ArrayList <>();
372372 for ( Object item : items ) {
@@ -445,18 +445,33 @@ protected Map<String, Object> toMap(Object value) throws LinkMLRuntimeException
445445 }
446446
447447 /**
448- * Checks that a raw object is a list, and casts it as such.
448+ * Turns a raw object into a list.
449+ * <p>
450+ * This checks that the given object is a list, and casts it as such. If it is
451+ * not a list, then an exception is thrown, unless the <code>wrap</code>
452+ * argument is set to <code>true</code>, in which case the value is wrapped into
453+ * a single item list.
449454 *
450455 * @param value The raw object to cast.
451- * @return The input object, cast into a list.
452- * @throws LinkMLRuntimeException If the raw object is not in fact a list.
456+ * @param wrap If <code>true</code> and <code>value</code> is not a list, then
457+ * return a newly created list containing only the value.
458+ * @return The input object as a list.
459+ * @throws LinkMLRuntimeException If the raw object is not in fact a list and
460+ * <code>wrap</code> is <code>false</code>.
453461 */
454462 @ SuppressWarnings ("unchecked" )
455- protected List <Object > toList (Object value ) throws LinkMLRuntimeException {
463+ protected List <Object > toList (Object value , boolean wrap ) throws LinkMLRuntimeException {
456464 if ( !(value instanceof List ) ) {
457- throw new LinkMLValueError (LIST_EXPECTED );
465+ if ( wrap ) {
466+ List <Object > l = new ArrayList <>();
467+ l .add (value );
468+ return l ;
469+ } else {
470+ throw new LinkMLValueError (LIST_EXPECTED );
471+ }
472+ } else {
473+ return (List <Object >) value ;
458474 }
459- return (List <Object >) value ;
460475 }
461476
462477 /**
0 commit comments