Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ExecutionContextSerializer implementation based on Gson #4151

Open
fmbenhassine opened this issue Jul 14, 2022 · 4 comments
Open

Add ExecutionContextSerializer implementation based on Gson #4151

fmbenhassine opened this issue Jul 14, 2022 · 4 comments

Comments

@fmbenhassine
Copy link
Contributor

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.

@fmbenhassine
Copy link
Contributor Author

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);
}

@fmbenhassine fmbenhassine modified the milestones: 5.0.0-RC1, 5.0.0-RC2 Oct 19, 2022
@fmbenhassine fmbenhassine modified the milestones: 5.0.0-RC2, 5.0.0 Nov 8, 2022
@fmbenhassine fmbenhassine modified the milestones: 5.0.0, 5.1.0 Nov 24, 2022
@fmbenhassine fmbenhassine modified the milestones: 5.1.0, 5.2.0 Sep 18, 2023
@ssjf409
Copy link

ssjf409 commented Dec 25, 2023

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?

@fmbenhassine
Copy link
Contributor Author

@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.

@ssjf409
Copy link

ssjf409 commented Jan 13, 2024

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.

@fmbenhassine fmbenhassine modified the milestones: 5.2.0, 6.0.0 Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants