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

Skipping over groovy metadata class + groovy test. #118

Merged
merged 9 commits into from
Feb 21, 2024

Conversation

Shounaks
Copy link
Contributor

@Shounaks Shounaks commented Feb 17, 2024

Issue: #93
Description: As per our discussion, we will be skipping serialization of Groovy related classes , i have added a sample groovy test case as well!

Reference taken from: https://github.com/FasterXML/jackson-databind/blob/db95863d6f48cb5695bf8e14af1e7af2ece8e52e/src/main/java/com/fasterxml/jackson/databind/util/BeanUtil.java#L205

@cowtowncoder
Copy link
Member

Ok, so, this would indeed avoid cyclic dependency but I have 2 concerns.

One is that it would prevent any all types in groovy.lang (and sub-packages) from being (de)serialized, not just metadata. Not sure this is a big problem but could be problematic.

Second: jackson-databind prevents serialization of all instances accessed via getMetaClass() that return type under groovy.lang, which seems more targeted and prevents inclusion of any value.
Approach here will still leave empty Object. To me, removal would seem preferable; and one that specifically targets property that is the problem.

@cowtowncoder
Copy link
Member

Ok, I am not sure I like this big code clean up, as part of changes. I am all for targeted pieces but wholesale cleanup seems unnecessary.

@Shounaks
Copy link
Contributor Author

Okay Will create keep this PR for just precise changes, and then create a seperate one for Code Cleanup. if its fine.

@Shounaks
Copy link
Contributor Author

Done! 👍👍


void testSimpleObject() throws Exception {
var data = JSON.std.asString(new MyClass())
var expected = """{"AAAAA_A_Field_Starting_With_Two_Capital_Letters":"XYZ","aDouble":0.0,"aPublicInitializedInteger":56,"aPublicInitializedIntegerObject":1516,"aPublicUninitializedInteger":0,"anInitializedIntegerObject":1112,"anInitializedPublicString":"stringData","anInitializedString":"ABC","anInteger":0,"anIntegerWithValue":12}"""
Copy link
Member

Choose a reason for hiding this comment

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

Was about to ask about var and triple quotes wrt JDK 8 before realizing this is Groovy :)

Copy link
Member

Choose a reason for hiding this comment

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

One question tho: how does this test get run? It doesn't look like it runs with ./mvnw clean test from main level...
And commenting out handling of Groovy metadata makes nothing fail (ditto for explicit fail() in test).

Maybe test would need to be under src/test/groovy instead of src/test/java?

Copy link
Member

Choose a reason for hiding this comment

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

* either removing that reference, or skipping over such references.
*/
protected static boolean isGroovyMetaClass(Class<?> clazz) {
return clazz.getName().startsWith("groovy.lang");
Copy link
Member

Choose a reason for hiding this comment

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

This needs to check for class name, not just package, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes correct!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially i implemented it to check for just MetaClassImpl, but after checking jackson-databind, i just replicated its exclusion.

https://github.com/FasterXML/jackson-databind/blob/db95863d6f48cb5695bf8e14af1e7af2ece8e52e/src/main/java/com/fasterxml/jackson/databind/util/BeanUtil.java#L205

is this correct? or should we go for targeted exclusions?

Copy link
Member

Choose a reason for hiding this comment

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

Note calling line:

https://github.com/FasterXML/jackson-databind/blob/db95863d6f48cb5695bf8e14af1e7af2ece8e52e/src/main/java/com/fasterxml/jackson/databind/util/BeanUtil.java#L59

which actually checks class name: helper method name is bit misleading I agree. But yes, I think we should target to just that class, unless proven something else is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

understood, I missed this code, will implement in a similar fashion.

@cowtowncoder cowtowncoder marked this pull request as ready for review February 21, 2024 00:56
@cowtowncoder
Copy link
Member

Ok: I was able to make groovy test actually run -- but it does not appear to trigger cyclic dependency even without change to BeanPropertyIntrospector. :-(

So not 100% sure how to trigger the problem being fixed, still.

@Shounaks
Copy link
Contributor Author

Shounaks commented Feb 21, 2024

Ok: I was able to make groovy test actually run -- but it does not appear to trigger cyclic dependency even without change to BeanPropertyIntrospector. :-(

So not 100% sure how to trigger the problem being fixed, still.

image
I am able to replicate failure, albeit a different exception. if i comment out these 2 lines of code.
image

@cowtowncoder
Copy link
Member

@Shounaks Does not fail for me if I change isGroovyMetaClass() to return false: everything passes without problem. Test class is executed (I can verify with Assert.fail()).

Could it be you are commenting out more than the new check, so that pre-existing checks for missing type or Object are not done?

@cowtowncoder
Copy link
Member

Oh wait. I can actually reproduce the issue via IDE (Eclipse) after installing Groovy plugin.

It just does not fail with Maven from command-line. This is bizarre...

@cowtowncoder
Copy link
Member

Ok. I really wish Maven was able to reproduce (to guard against regression), but it is what it is. Will merge in for 2.17.0(-rc1).

@cowtowncoder cowtowncoder merged commit 5d6be9b into FasterXML:2.17 Feb 21, 2024
4 checks passed
@Shounaks
Copy link
Contributor Author

Oh wait. I can actually reproduce the issue via IDE (Eclipse) after installing Groovy plugin.

It just does not fail with Maven from command-line. This is bizarre...

yeah, this is strange. Never would've guessed this can be a point of failure. 😆

@cowtowncoder
Copy link
Member

Yeah more commonly it's the opposite: some problem with IDE, works as expected via Maven from shell.
I wonder if part of this might be compiler plug-in settings: for jackson-jr we are compiling with minimum debug information to reduce jar size. Not sure that is related, but I did notice that compiling from shell vs IDE compiling has some effect. Could of course just be wrt Groovy integration too.

Shounaks added a commit to Shounaks/jackson-jr that referenced this pull request Feb 27, 2024
@Shounaks Shounaks deleted the issue-#93 branch February 28, 2024 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants