scijava-common
                                
                                 scijava-common copied to clipboard
                                
                                    scijava-common copied to clipboard
                            
                            
                            
                        Allow differentiating between lossy and lossless object conversion
Currently we can ask ConvertService whether a certain conversion is supported via:
convertService.supports(sourceObject, targetType)
It would be great to have some possibility to differentiate what degree of conversion is desired:
- Conversion from any ObjecttoStringis possible (viatoString()) but rarely lossless. Even for bidirectional cases like (FiletoString) and (StringtoFile), this can be lossless but not always desired.
- When running a script that has an Imginput, but no image is currently available, we might ask the user to supply aFileinstead to then load the image from file. This (FiletoImg) conversion won't always work, but it would be nice if some service would support it in a failure-tolerant way upon request.
How about introducing different 'modes' of conversion, like STRICT, FLEXIBLE and INSISTENT?
The lossy conversion from Dataset (or, in general, from any Object) to String is currently preventing me from providing a useful batch processing for Dataset, Img etc.: any module accepting String inputs will be recognized as "batchable", which is almost never what you want.
Knowledge about "lossiness" of a conversion would also be useful to allow choice of the best possible column type when post-processing module outputs, see https://github.com/scijava/scijava-table/issues/5.
DoubleType -> DoubleColumn
double -> DoubleColumn
UnsignedByteType -> IntColumn
UnsignedIntType -> LongColumn
etc.
Currently I don't know a way to decide this, because ConvertService supports e.g. double to int conversion without complaining.