Optional field with default value in GtfsTransformStrategy implementation not injected with default value
kurtraschke opened this issue · comments
Summary:
A field annotated with @CsvField(optional = true, defaultValue = "foo")
in a class which implements GtfsTransformStrategy
is not injected with the default value, if a value is not specified in the transform JSON which invokes the class (i.e. as described here).
Steps to reproduce:
- Implement
GtfsTransformStrategy
in a class. - Introduce a field annotated with
@CsvField(optional = true, defaultValue = "foo")
. - Run the transformer with a transform JSON which invokes the class, but does not specify a value for the optional field.
Expected behavior:
The field should be injected with the default value.
Observed behavior:
The field is not injected, and remains null
.
Platform:
Helium:onebusaway-gtfs-modules kurt$ uname -a
Darwin Helium.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64
Helium:onebusaway-gtfs-modules kurt$ java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
It seems like the root cause lies somewhere in onebusaway-csv-entities
- I can't find anywhere where it actually makes use of the default value. The closest we get is in AbstractFieldMapping.isMissing()
, but presumably there needs to be something in DefaultFieldMapping.translateFromCSVToObject()
which actually uses the default value.