Skip to content

Add ability to amend trusted classes in Jackson2ExecutionContextStringSerializer #3787

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

Merged
merged 1 commit into from
Oct 16, 2020

Conversation

fmbenhassine
Copy link
Contributor

This PR is for #3765. It adds the ability to specify additional trusted classes (at construction time of the Jackson2ExecutionContextStringSerializer) without having to provide a custom object mapper.

The usage of varargs in the constructor of Jackson2ExecutionContextStringSerializer makes the change backward compatible with 4.2.

…gSerializer

This commit adds the ability to specify additional trusted
classes without having to provide a custom object mapper.

Issue spring-projects#3765
@fprochazka
Copy link

This looks like it solves it for me. It's still not very easy to replace the service itself (Jackson2ExecutionContextStringSerializer), but now at least I don't have to copy&paste the entire class. Thanks!

@fmbenhassine fmbenhassine merged commit a0bcd7c into spring-projects:master Oct 16, 2020
@fmbenhassine fmbenhassine deleted the BATCH-3765 branch October 16, 2020 09:37
@nstdio
Copy link
Contributor

nstdio commented Dec 21, 2020

@benas Seems this change is not binary compatible with client compiled against 4.2.x.

@fmbenhassine
Copy link
Contributor Author

@nstdio This enhancement/feature has not been backported to 4.2.x, even though my initial comment implies it. We typically backport bug fixes only to patch releases of previous supported lines (4.2.x is approaching its EOL anyway). Anything preventing you from upgrading to 4.3?

@nstdio
Copy link
Contributor

nstdio commented Jan 5, 2021

@benas Thanks for your response. Great work! We already upgraded to 4.3 with minimal effort.

The issue was that internal library was compiled against 4.2.x. After upgrading to Spring Batch version to 4.3 in the consumer project, we've got java.lang.NoSuchMethodError. The runtime cannot find the Jackson2ExecutionContextStringSerializer.<init>() method, because in 4.3 constructor signature was changed.

@duthng
Copy link

duthng commented May 10, 2021

Hello @benas!

thank you for the effort putting this so far, I would like to ask, how is that possible to return a customized Jackson2ExecutionContextStringSerializer, and this Serializer will be used in default spring-batch configuration? Until now we don't have explicit configuration for JobRepository and maybe others related classes (Beans).

For example would below code would work?

@Configuration
public class SpringBatchAdditinalConfiguration {

  @Bean
  public Jackson2ExecutionContextStringSerializer jackson2ExecutionContextStringSerializer (
      return new Jackson2ExecutionContextStringSerializer("my.Class1", "my.Class2");
  }
}

If it would be not possible the which classes (JobExplorer, JobRepository ?) should I explicitly create. Do you have an example how to just only overwrite Jackson2ExecutionContextStringSerializer, but leave everything else (i.e. JobExplorer, JobRepository) with least changes as possible?

Kind regards
Thanh

@fmbenhassine
Copy link
Contributor Author

@dthng You need to provide a custom BatchConfigurer and override getJobRepository(), see Configuring a JobRepository. You can set your custom serializer on the factory bean used to create the job repository (same approach for the job explorer if needed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jackson2ExecutionContextStringSerializer: customization
4 participants