scijava-common icon indicating copy to clipboard operation
scijava-common copied to clipboard

Allow differentiating between lossy and lossless object conversion

Open imagejan opened this issue 8 years ago • 2 comments

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 Object to String is possible (via toString()) but rarely lossless. Even for bidirectional cases like (File to String) and (String to File), this can be lossless but not always desired.
  • When running a script that has an Img input, but no image is currently available, we might ask the user to supply a File instead to then load the image from file. This (File to Img) 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?

imagejan avatar Aug 28 '17 13:08 imagejan

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.

imagejan avatar Aug 08 '18 09:08 imagejan

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.

imagejan avatar Jan 13 '19 18:01 imagejan