aws / aws-swf-flow-library

AWS Simple Workflow Flow framework library
Apache License 2.0
61 stars 54 forks source link

SpringActivityWorker.addActivitiesImplementation does not use the DataConverter set in setDataConverter method; uses default instead #13

Open kiiadi opened 7 years ago

kiiadi commented 7 years ago

(moved from https://github.com/aws/aws-sdk-java/issues/925 issue opened by @jonkerlinger ) When calling setActivitiesImplementation or addActivitiesImplementation on the SpringActivityWorker, the single-arg POJOActivityImplementationFactory.addActivitiesImplementation, which ultimately will only use the default DataConverter or the Activities annotation-specified DataConverter. Even though the POJO implementation of SpringActivityWorker allows users to specify the DataConverter, it is not used when adding ActivitiesImplementations.

To work around it, I've had to extend SpringActivityWorker with something like this:

    @Override
    public List<ActivityType> addActivitiesImplementation(Object activitiesImplementation) {
        try {
            Field field = SpringActivityWorker.class.getDeclaredField("factory");
            field.setAccessible(true);
            POJOActivityImplementationFactory factory = (POJOActivityImplementationFactory) field.get(this);

            return factory.addActivitiesImplementation(activitiesImplementation, factory.getDataConverter());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

The override works fine for now, but is hacky. It seems that since setDataConverter sets the factory DataConverter, then that value should also be passed into the addActivitiesImplementation call, or the POJO factory should use the dataConverter field if present, rather than just looking at the annotation.