Skip to content

Commit c74cb07

Browse files
ctruedenimagejan
authored andcommitted
ResultsPostprocessor: handle Object outputs better
If the output type is Object, let's look at the actual object value when deciding whether to lump it into the table. We use this heuristic here because an Object output is very often the default "result" output, and we want that value to show in the table if its type is compatible.
1 parent 15980d2 commit c74cb07

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/main/java/net/imagej/table/process/ResultsPostprocessor.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void process(final Module module) {
7070
final String name = output.getName();
7171
if (module.isOutputResolved(name)) return;
7272
if (module.getOutput(name) == null) return;
73-
if (!isSimpleType(output.getType())) return;
73+
if (!isSimple(module, output)) return;
7474
outputs.add(output);
7575
});
7676

@@ -104,9 +104,21 @@ public void process(final Module module) {
104104

105105
// -- Helper methods --
106106

107+
private boolean isSimple(final Module m, final ModuleItem<?> item) {
108+
final Class<?> type = item.getType();
109+
return isSimpleType(type) || //
110+
// NB: The output is typed on Object -- maybe the default result output.
111+
// In this case, let's decide based on the actual value rather than type.
112+
type == Object.class && isSimpleValue(item.getValue(m));
113+
}
114+
107115
private boolean isSimpleType(final Class<?> type) {
108116
return ClassUtils.isText(type) || //
109117
ClassUtils.isNumber(type) || //
110118
ClassUtils.isBoolean(type);
111119
}
120+
121+
private boolean isSimpleValue(final Object o) {
122+
return o != null && isSimpleType(o.getClass());
123+
}
112124
}

0 commit comments

Comments
 (0)