spring-batch
spring-batch copied to clipboard
Add ExecutionContextSerializer implementation based on Gson
The goal of this issue is to add an implementation of ExecutionContextSerializer
based on Google's Gson, to give our users the choice between at least two implementations (ie Jackson and Gson) out-of-the-box, as mentioned in #4140.
For some types, a serialization round trip with gson
does not work OOTB. The following tests are failing with gson
2.9.1
:
@Test
void testGsonSerializationRoundTripForDate() {
Gson gson = new Gson();
Date src = new Date();
String s = gson.toJson(src);
Date date = gson.fromJson(new StringReader(s), Date.class);
Assertions.assertEquals(date, src);
}
@Test
void testGsonSerializationRoundTripForLocalDate() {
Gson gson = new Gson();
LocalDate src = LocalDate.now();
String s = gson.toJson(src);
LocalDate date = gson.fromJson(new StringReader(s), LocalDate.class);
Assertions.assertEquals(date, src);
}
Hi. @fmbenhassine
Could I handle this issue? If you are okay, I want to try to implement it. I already took a look at your draft.
Do I have to make my branch from GH-4151 of your repository?
@ssjf409 Sure! Thank you for your offer to help. You can start from the latest main
branch if you want to contribute a new implementation.
My attempt was almost done, except that I couldn't figure out how to make gson
serialize the type information (similar to jackson which writes an attribute @class: fully.qualified.class.name
). I believe this should be configured on the gson
instance, but I could not find how at the time. Do you know how to do that? I prefer digging further and try to delegate this to the serializarion library than handling it manually in the execution serializer implementation of Spring Batch.
Thanks for your guide.👍
Actually. I didn't think about that you mentioned (I couldn't figure out how to make gson serialize the type information (similar to jackson which writes an attribute @class: fully.qualified.class.name)
). I just it is enough to meet to condition for roundtrip.
However, I try to find a way.