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 transfers for using arguments #16

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

nielsdebruin
Copy link
Contributor

What's changed?

The RemoveDoublyAnnotatedCodehausAnnotations recipe has been extended with the functionality to transfer the value of "using" in the codehaus annotations@JsonSerialize(using=XYZ) to the faster XML annotation.The transfer only occurs if no value for using has been specified in the fasterxml annotation. An option has been added to enable or disable this behavior

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

@Laurens-W @timtebeek

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

github-actions[bot]

This comment was marked as outdated.

@nielsdebruin nielsdebruin marked this pull request as ready for review October 23, 2024 12:52
@nielsdebruin nielsdebruin added the enhancement New feature or request label Oct 23, 2024
@timtebeek
Copy link
Contributor

I'd prefer to keep RemoveDoublyAnnotatedCodehausAnnotations as a recipe that merely removes annotations, and does not itself do any conversion.

Can we move this visitor into a either the existing JsonIncludeAnnotation recipe, or a standalone recipe?

@nielsdebruin nielsdebruin changed the title Add transfers for using arguments WIP: Add transfers for using arguments Oct 23, 2024
@timtebeek timtebeek marked this pull request as draft October 23, 2024 15:21
@timtebeek timtebeek changed the title WIP: Add transfers for using arguments Add transfers for using arguments Oct 23, 2024
timtebeek and others added 3 commits October 24, 2024 11:33
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work & rework here @nielsdebruin ; ended up removing the troublesome auto format; when in doubt that's typically easiest.

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few more polishes, like also converting known serializer packages to fasterxml databind. Thanks for getting this most of the way there!

Comment on lines 63 to 64
@JsonSerialize(include = NON_NULL, using = None.class)
@com.fasterxml.jackson.databind.annotation.JsonSerialize(using = None.class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I found slightly odd about the "after" usage example here is that we're one-to-one moving the argument over, whereas the using argument here, as well as the contentUsing, keyUsing and nullsUsing sibling only accept a FasterXml JsonSerializer, whereas the moved argument is a Codehaus JsonSerialzer, That means after this recipe the code would not yet compile. Compare the before and after packages:

image image

That means we likely need to expand the converted packages (ideally) and types (for exceptional cases) seen here:

name: org.openrewrite.java.jackson.CodehausClassesToFasterXML
displayName: Migrate classes from Jackson Codehaus (legacy) to Jackson FasterXML
description: >-
In Jackson 2, the package and dependency coordinates moved from Codehaus to FasterXML.
recipeList:
- org.openrewrite.java.jackson.codehaus.JsonIncludeAnnotation
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.codehaus.jackson.map.JsonSerializer
newFullyQualifiedTypeName: com.fasterxml.jackson.databind.JsonSerializer
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.codehaus.jackson.map.annotate.JsonSerialize$Inclusion
newFullyQualifiedTypeName: com.fasterxml.jackson.annotation.JsonInclude$Include
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.codehaus.jackson.map.annotate.JsonSerialize
newFullyQualifiedTypeName: com.fasterxml.jackson.databind.annotation.JsonSerialize
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.codehaus.jackson.map.ObjectMapper
newFullyQualifiedTypeName: com.fasterxml.jackson.databind.ObjectMapper
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.codehaus.jackson.map.SerializationConfig$Feature
newFullyQualifiedTypeName: com.fasterxml.jackson.databind.SerializationFeature
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.codehaus.jackson.map.DeserializationConfig$Feature
newFullyQualifiedTypeName: com.fasterxml.jackson.databind.DeserializationFeature
- org.openrewrite.java.ChangePackage:
oldPackageName: org.codehaus.jackson.annotate
newPackageName: com.fasterxml.jackson.annotation
recursive: true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed up in 736fce0.

@timtebeek timtebeek marked this pull request as ready for review October 24, 2024 09:52
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we merge; would you mind handling the other using arguments the same?

contentUsing, keyUsing and nullsUsing

@nielsdebruin
Copy link
Contributor Author

Before we merge; would you mind handling the other using arguments the same?

contentUsing, keyUsing and nullsUsing

On it

// Map from codehaus -> fasterxml annotation
Map<J.Annotation, J.Annotation> doubleAnnotated = new FindDoublyAnnotatedVisitor().reduce(tree, new HashMap<>());

transferArgument(doubleAnnotated, "using");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could keep a list of field names that should be transferred and reduce this to a single statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants