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

BlackBird not support fluent setter #123

Closed
wujimin opened this issue Dec 28, 2020 · 7 comments · Fixed by #124
Closed

BlackBird not support fluent setter #123

wujimin opened this issue Dec 28, 2020 · 7 comments · Fixed by #124
Milestone

Comments

@wujimin
Copy link

wujimin commented Dec 28, 2020

Environment

  • jdk 11
  • jackson 2.12.0 with BlackBird

Reproduce case

define a model with fluent setter

public class BlackBirdBug {
  public static class Model {
      private int value = 10;

      public int getValue() {
          return value;
      }

      public Model setValue(int value) {
          this.value = value;

          return this;
      }
  }

  public static void main(String[] args) throws JsonProcessingException {
      ObjectMapper mapper = new ObjectMapper()
          .registerModule(new BlackbirdModule());
      String json = mapper.writeValueAsString(new Model());
      System.out.println(json);

      Model model = mapper.readValue(json, Model.class);
      System.out.println(model.getValue());
  }
}

will throw exception:

Caused by: java.lang.invoke.LambdaConversionException: Type mismatch for instantiated parameter 1: int is not a subtype of class java.lang.Object
	at [email protected]/java.lang.invoke.AbstractValidatingLambdaMetafactory.checkDescriptor(AbstractValidatingLambdaMetafactory.java:308)
	at [email protected]/java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:294)
	at [email protected]/java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:328)
	at com.fasterxml.jackson.module.blackbird.deser.BBDeserializerModifier.createSetter(BBDeserializerModifier.java:221)
	at com.fasterxml.jackson.module.blackbird.deser.BBDeserializerModifier.nextProperty(BBDeserializerModifier.java:179)
	at com.fasterxml.jackson.module.blackbird.deser.BBDeserializerModifier.findOptimizableProperties(BBDeserializerModifier.java:126)
	... 14 more

we are trying switch from AfterBurner to BlackBird, because AfterBurner not support ToStringSerializer via @JsonSerialize in boolean oroperty

cowtowncoder added a commit that referenced this issue Jan 1, 2021
@cowtowncoder
Copy link
Member

@wujimin Thank you for reporting this: I can reproduce the problem.

@stevenschlansker Looks like code might assume that all setters are of type void? I added a test under "..../failing" ( named BasicDeserialize123Test) and will see if I can see how this could be fixed, but if you have a chance to look at some point that'd be great as you know code much better :) .

@stevenschlansker
Copy link
Contributor

That could be it, or maybe a spot where the VM would autobox for us but invokeExact doesn't. Either way I can take a look in the next few days (on vacation this week technically, happy new year all! )

@cowtowncoder
Copy link
Member

@stevenschlansker yeah that sounds plausible. Return type is part of the signature, anyway. Could either filter out such cases (not optimize) or ideally handle, either would work.
Happy new year -- no rush obviously, I just added note as I had a chance to look at things reported for 2.12, before modest New Year's celebrations. :-)

@wujimin
Copy link
Author

wujimin commented Jan 4, 2021

Happy new year

https://github.com/apache/servicecomb-java-chassis/blob/master/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/LambdaMetafactoryUtils.java#L131

commit: apache/servicecomb-java-chassis@d0655d7#diff-1bddb21d3057a94ecd88f453fd874a04f13dc1ae4b5093f6c1e9838fdb576246

We also had this problem most six months ago, and we just force set the return type to void to avoid the problem

@stevenschlansker
Copy link
Contributor

Makes sense. Should be an easy enough fix.

@stevenschlansker
Copy link
Contributor

@wujimin, it turned out to not be quite the same bug, but if you have a chance please verify that #124 fixes your issue

@wujimin
Copy link
Author

wujimin commented Jan 5, 2021

@stevenschlansker
i have verified the new code
it fixed my issue.
thanks.

and find a new issue of https://github.com/FasterXML/jackson-modules-base/blob/2.12/blackbird/README.md

<dependency>
  <groupId>com.fasterxml.jackson.modules</groupId>
  <artifactId>jackson-module-blackbird</artifactId>
</dependency>

groupId should be com.fasterxml.jackson.module

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