Repository navigation
Map fastjson features to the right fastjson2 enum and migrate @JSONField imports - #1342
Merged
Merged
Conversation
…Feature` to `JSONReader.Feature` The write-side `SerializerFeature` was mapped to the read-side `JSONReader.Feature` and vice versa, and the dotted nested-type names left the references unqualified and unimported, so `JSON.toJSONString(o, SerializerFeature.PrettyFormat)` no longer compiled after the migration.
….fastjson2.annotation` `ChangePackage` for `com.alibaba.fastjson` is not recursive, so `@JSONField`, `@JSONType`, `@JSONCreator` and `@JSONPOJOBuilder` kept their fastjson 1 imports while the dependency was swapped to fastjson2. Those four have direct counterparts in `com.alibaba.fastjson2.annotation` (`@JSONPOJOBuilder` is `@JSONBuilder` there); other subpackages don't map 1:1, so they are not made recursive.
22 of 72 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes G8 from #1330.
MigrateFastjsonForJakarta10(part ofJakartaEE10) mapped fastjson 1's write-sideSerializerFeatureto fastjson2's read-sideJSONReader.Featureand vice versa. The dotted nested-type names also left references unqualified and unimported, soJSON.toJSONString(o, SerializerFeature.PrettyFormat)becameJSON.toJSONString(o, Feature.PrettyFormat)with no import. The targets are now swapped and use the$notationChangeTypeexpects for nested types.ChangePackage com.alibaba.fastjsonisn't recursive, so@JSONFieldand the other annotations kept their fastjson 1 imports after the dependency was swapped to fastjson2. I didn't make it recursive because the other subpackages (serializer,parser,support.*) don't map 1:1 to fastjson2: a recursive rename would just move the unmapped types into fastjson2 packages that don't exist. Instead there are now explicitChangeTypes for the four annotation types.@JSONPOJOBuildermaps to@JSONBuilder.Things a reviewer should know:
javap. 20 of the 30SerializerFeatureconstants exist inJSONWriter.Feature, includingPrettyFormat,WriteMapNullValue,WriteClassNameandBeanToArray. The ones that don't includeDisableCircularReferenceDetect,WriteDateUseDateFormat,SortField,QuoteFieldNames,UseISO8601DateFormatandSkipTransientField. Only 6 of the 27parser.Featureconstants exist inJSONReader.Feature:AllowUnQuotedFieldNames,SupportArrayToBean,SupportAutoType,InitStringFieldAsEmpty,NonStringKeyAsStringandErrorOnEnumNotMatch. This PR doesn't map the renamed or removed constants. Before it, none of them resolved.serialzeFeatures/parseFeatureswere renamed toserializeFeatures/deserializeFeaturesin fastjson2, and those aren't renamed here either.ChangeTypebug: changing a top-level type to a nested type that's used as a static-field qualifier also adds an unusedimport com.alibaba.fastjson2.JSONWriter.Feature;. It reproduces with JDK types too (TextStyle.FULLtoLocale$Categorygivesimport java.util.Locale.Category;next toLocale.Category.FULL). On its own that's harmless, so the expected outputs include it. A file that uses both enums ends up importing twoFeatures, though, and won't compile.readerAndWriterFeatureInOneFilecovers that case as@ExpectedToFailuntil the fix lands in rewrite-java.testRuntimeOnlydependency so the tests can parse againstclasspath("fastjson").Verified with
./gradlew test --tests 'org.openrewrite.java.migrate.jakarta.MigrateFastjsonForJakarta10Test' --tests 'org.openrewrite.java.migrate.jakarta.JakartaEE10Test' --tests 'org.openrewrite.java.migrate.jakarta.JakartaEE11Test': 3 passed, 1 expected to fail. Before the fix, all three fastjson tests failed: the enum tests produced an unqualified, unimportedFeature, and@JSONFieldwas left untouched.recipeCsvGenerateonly changed the counts for this recipe,JakartaEE10andJakartaEE11.