6 Replies Latest reply on Jan 14, 2019 7:33 AM by g.hohl

    WildFly 14: Ignore POJO setter during JSON serialization / deserialization

    g.hohl

      Hi everyone,

       

      we have an application which was running on WildFly 10 / JEE7 so far. Now we ported it to WildFly 14 / JEE8 (and it seems we will move to WildFly 15 soon).

      In that application we have a POJO looking like this:

       

      @JsonInclude(Include.NON_NULL)
      public class StateInformation {
          private State state;
          private String stateMessage;
          
          public Information() {
              super();
          }
          
          public State getState() {
              return this.state;
          }
          
          public void setState(State state) {
              this.state = state;
          }
          
          public String getStateMessage() {
              return this.stateMessage;
          }
          
          public void setStateMessage(String stateMessage) {
              this.stateMessage = stateMessage;
          }
          
          public boolean setStateIfNotSet(State state, String stateMessage) {
              if (state == null)
                  throw new IllegalArgumentException("Argument state is null.");
              if (stateMessage == null)
                  throw new IllegalArgumentException("Argument stateMessage is null.");
              if (this.state == null) {
                  this.setState(state)
                  this.setStateMessage(stateMessage);
                  return true;
              }
              return false;
          }
      }

       

      Until now that class worked perfectly. But since we switched, we get an exception:

      RESTEASY008205: JSON Binding serialization error javax.json.bind.JsonbException: Invalid count of arguments for setter: public boolean org.example.rest.StateInformation.setStateIfNotSet(org.example.rest.State,java.lang.String): javax.ws.rs.ProcessingException: RESTEASY008205: JSON Binding serialization error javax.json.bind.JsonbException: Invalid count of arguments for setter: public boolean org.example.rest.StateInformation.setStateIfNotSet(org.example.rest.State,java.lang.String)

          at org.jboss.resteasy.plugins.providers.jsonb.JsonBindingProvider.writeTo(JsonBindingProvider.java:149)

      During the serialization / deseralization that method shouldn't be used at all. And before it wasn't also a problem, but now it is.

      I tried to annotate the method using:

      • com.fasterxml.jackson.annotation.JsonIgnore
      • javax.json.bind.annotation.JsonbTransient
      • javax.xml.bind.annotation.XmlTransient

      But none of them does the job (also no combination).

       

      Does anyone have any idea what has changed? And how we can fix it?

        • 1. Re: WildFly 14: Ignore POJO setter during JSON serialization / deserialization
          g.hohl

          I realized that I'm using the standalone.xml in my development server, also we use the standalone-full.xml in our productive system. But that - unfortunately - didn't change anything.

          • 2. Re: WildFly 14: Ignore POJO setter during JSON serialization / deserialization
            lafr

            Since Wildfly 13 Yasson is used instead of Jackson. Wildfly 14 is using Yasson 1.0.1, Wildfly 15 is using Yasson 1.0.2.

             

            Before Yasson 1.0.2, every method starting with "set" was assumed to be a setter, if there is more than one argument then, an exception is thrown.

            This was fixed with Ignore property methods with incorrect num args · eclipse-ee4j/yasson@eaebfcb · GitHub  included in 1.0.2 ff.

             

            So I see these options for you:

            - rename the problematic method so that is does not start with "set"

            - try to replace the yasson library ues in WF 14 with version 1.0.2. Don't know if it's possible.

            - skip WF 14 and directly go to WF 15.

            • 3. Re: WildFly 14: Ignore POJO setter during JSON serialization / deserialization
              g.hohl

              Hello Frank,

               

              thanks for your fast reply.
              I see. Maybe switching to WF 15 is the best option as I've renamed the method, but get a different error now (Stack-Trace is shorten):

              RESTEASY008205: JSON Binding serialization error java.lang.IllegalArgumentException: wrong number of arguments: javax.ws.rs.ProcessingException: RESTEASY008205: JSON Binding serialization error java.lang.IllegalArgumentException: wrong number of arguments

                  at org.jboss.resteasy.plugins.providers.jsonb.JsonBindingProvider.writeTo(JsonBindingProvider.java:149)

                  at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.writeTo(AbstractWriterInterceptorContext.java:137)

              And I'm not really sure what this exception want to tell me.
              I'll give feedback if switching to WF 15 solved my problem (totally).

              • 4. Re: WildFly 14: Ignore POJO setter during JSON serialization / deserialization
                g.hohl

                Okay, I tested it with WildFly-15.0.1-Final and everything is working fine now. I can name the method "setXXX", having a different number of arguments than just 1 and not needing any annotations.

                 

                Thanks a lot.

                • 5. Re: WildFly 14: Ignore POJO setter during JSON serialization / deserialization
                  ctomc

                  Exception you get now just tells you that Yasson cannot map pojo properly, from code you paste I think setStateIfNotSet bothers him, as  it starts with "set" but has more than just one parameter (which would comply to pojo concept)

                  • 6. Re: WildFly 14: Ignore POJO setter during JSON serialization / deserialization
                    g.hohl

                    Thanks Tomaz. As Frank already pointed out, it is a bug in Yasson. In the version shipped with WF 15 the problem doesn't occur. The 2nd exception I posted is after I renamed the specific methods. So it's not that method anymore which bothers him, but something else. It would have been nice, if the exception would contain which class / method / field it has a problem with... Anyway: it is running now and I'm happy. Of course I could have started debugging it into the depths of WF and Yasson, but currently I don't see any benefit in doing so.