4

I want to add a boolean type parameter to spring JobParameters. But here: http://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/core/JobParameter.ParameterType.html it says JobParameter type accepts only Date, Double, Long, String.

How can I add a boolean or any custom object to JobParameters?

1
  • 1
    use a long (0 means false,1 or != 0 means true); if you wanna type checking use a function boolean isJobParamTrue(Long p) {...} May 11, 2015 at 11:36

1 Answer 1

6

Only way to do it is to use some of supported types. You can, as @lucabassoricci suggested, use long or you can use String and do conversion back and forth. You are controlling both setting and reading of parameters so this is not that bad, you will always get either "true" or "false" string and you can do parse:

Boolean boolean1 = Boolean.valueOf("true");
boolean boolean2 = Boolean.parseBoolean("true");

As for setting parameter you can do:

Boolean.toString(true);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.