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

Ignore generated methods for default arguments #603

Merged

Conversation

TimMoore
Copy link
Contributor

@TimMoore TimMoore commented Sep 9, 2022

When a method with default arguments has a name that matches JavaBeans property conventions, the generated method that computes the default argument expression is detected as a property.

@TimMoore
Copy link
Contributor Author

TimMoore commented Sep 9, 2022

This was discovered from this Stack Overflow question https://stackoverflow.com/q/73655638/29470

@@ -47,7 +47,7 @@ object ScalaAnnotationIntrospector extends NopAnnotationIntrospector with ValueI
override def hasIgnoreMarker(m: AnnotatedMember): Boolean = {
val name = m.getName
//special cases to prevent shadow fields associated with lazy vals being serialized
name == "0bitmap$1" || name.endsWith("$lzy1") || super.hasIgnoreMarker(m)
name == "0bitmap$1" || name.endsWith("$lzy1") || name.contains("$default$") || super.hasIgnoreMarker(m)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know if this is really the best way to filter these methods out, but it's the best way I could find.

Based on the spec at https://docs.scala-lang.org/sips/named-and-default-arguments.html#default-arguments-1

Copy link
Member

Choose a reason for hiding this comment

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

thanks - probably the best way to go

@TimMoore
Copy link
Contributor Author

TimMoore commented Sep 9, 2022

I wrote this test-first. Here are the failures that result without the change to ScalaAnnotationIntrospectorModule:

[info] - should ignore a generated default argument method *** FAILED ***
[info]   [[Property 'value$default$1'; ctors: null, field(s): null, getter(s): [method com.fasterxml.jackson.module.scala.introspect.ScalaAnnotationIntrospectorTest$GeneratedDefaultArgumentClass#getValue$default$1()][visible=true,ignore=false,explicitName=false], setter(s): null]] was not empty (ScalaAnnotationIntrospectorTest.scala:250)
...
[info] - should not find properties for default arguments *** FAILED ***
[info]   "{["value$default$1":"default"]}" did not equal "{[]}" (CaseClassSerializerTest.scala:207)
[info]   Analysis:
[info]   "{["value$default$1":"default"]}" -> "{[]}"

@pjfanning pjfanning merged commit d8da222 into FasterXML:2.14 Sep 9, 2022
pjfanning pushed a commit that referenced this pull request Sep 9, 2022
Co-authored-by: Tim Moore <tim.moore@lightbend.com>
@TimMoore TimMoore deleted the ignore-generated-default-arg-methods branch September 9, 2022 11:27
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.

2 participants