Skip to content

Commit 42db182

Browse files
committed
Make services optional for array/string converters
Especially the ParseService, because otherwise, if you include the ConvertService in your context without the ParseService, you'll see warnings that the StringToArrayConverter plugin cannot be instantiated.
1 parent 14f4e47 commit 42db182

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/main/java/org/scijava/convert/ArrayToStringConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
@Plugin(type = Converter.class, priority = Priority.VERY_LOW)
5151
public class ArrayToStringConverter extends AbstractConverter<Object, String> {
5252

53-
@Parameter private ConvertService convertService;
53+
@Parameter(required = false)
54+
private ConvertService convertService;
5455

5556
@Override public boolean canConvert(final Class<?> src, final Class<?> dest) {
5657
if (src == null) return false;
@@ -60,6 +61,7 @@ public class ArrayToStringConverter extends AbstractConverter<Object, String> {
6061
}
6162

6263
@Override public boolean canConvert(final Object src, final Class<?> dest) {
64+
if (convertService == null) return false;
6365
if (!canConvert(src.getClass(), dest)) return false;
6466
if (Array.getLength(src) == 0) return true;
6567
return convertService.supports(Array.get(src, 0), dest);

src/main/java/org/scijava/convert/StringToArrayConverter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
@Plugin(type = Converter.class, priority = Priority.VERY_LOW)
5353
public class StringToArrayConverter extends AbstractConverter<String, Object> {
5454

55-
@Parameter
55+
@Parameter(required = false)
5656
private ConvertService convertService;
5757

58-
@Parameter
58+
@Parameter(required = false)
5959
private ParseService parseService;
6060

6161
private final ExpressionParser parser = new ExpressionParser();
@@ -75,6 +75,7 @@ public boolean canConvert(final Object src, final Type dest) {
7575

7676
@Override
7777
public boolean canConvert(final Object src, final Class<?> dest) {
78+
if (convertService == null || parseService == null) return false;
7879

7980
// First, ensure the base types conform
8081
if (!canConvert(src.getClass(), dest)) return false;

0 commit comments

Comments
 (0)