Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add boolean type parameter to spring batch JobParameter?

Tags:

spring-batch

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?

like image 509
Vijay Kumar Avatar asked Nov 01 '25 00:11

Vijay Kumar


1 Answers

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);
like image 75
Nenad Bozic Avatar answered Nov 04 '25 19:11

Nenad Bozic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!