jersey
  1. jersey
  2. JERSEY-2200

Double parameters returned in json when a Boolean parameter starts with "is"

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.17
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None

      Description

      Using jersey-core, jersey-json, jersey-server, jersey-servlet. All versions 1.17.1

      The response object for my REST API has the following parameter

      @XmlElement(name = "isVATIncluded", required = true)
      private Boolean isVATIncluded

      What happens is that there is added an extra parameter "vatincluded" in my json response, in addition to "isVATIncluded". "vatincluded" has the same value as "isVATIncluded".

      If I change the parameter name, the problem is solved and "vatincluded" is no longer in my json response. For instance, this works:
      @XmlElement(name = "isVATIncluded", required = true)
      private Boolean vatIncluded;

        Activity

        Hide
        Jakub Podlesak added a comment - - edited

        I suggest you switch to using Jackson JSON provider. See [1] for details on the POJO mapping feature, that would be required in that case.

        Does it resolve your issue?

        Or do you use Jackson already and it still does not work? Could you please provide some more details on your setup?

        Thanks!

        [1]https://jersey.java.net/documentation/1.17/json.html#json.pojo.approach.section

        Show
        Jakub Podlesak added a comment - - edited I suggest you switch to using Jackson JSON provider. See [1] for details on the POJO mapping feature, that would be required in that case. Does it resolve your issue? Or do you use Jackson already and it still does not work? Could you please provide some more details on your setup? Thanks! [1] https://jersey.java.net/documentation/1.17/json.html#json.pojo.approach.section
        Hide
        VingeF added a comment -

        Hi Jakub

        Im not using a mapper. I'm sure that would be possible, but using the setup I showed in description has worked out fine. XmlRootElement and XmlElement from java.xml.bind.annotation does the trick. Also, my issue is resolved by changing the parameter name to "vatIncluded", so I'm happy. The JSON is not affected by this, because the XmlElement defines the name in the JSON.

        For me it seemed like an error when an key is added/removed to the JSON simply because of the naming of parameter in the class. I thought I should report it, that's all.

        Best regards
        Øyvind

        Show
        VingeF added a comment - Hi Jakub Im not using a mapper. I'm sure that would be possible, but using the setup I showed in description has worked out fine. XmlRootElement and XmlElement from java.xml.bind.annotation does the trick. Also, my issue is resolved by changing the parameter name to "vatIncluded", so I'm happy. The JSON is not affected by this, because the XmlElement defines the name in the JSON. For me it seemed like an error when an key is added/removed to the JSON simply because of the naming of parameter in the class. I thought I should report it, that's all. Best regards Øyvind
        Hide
        Jakub Podlesak added a comment -

        Hi Øyvind,

        Thanks for the clarification. I am then going to resolve this as won't fix. Others will still have a chance to see
        how to workaround if they also experience above described behaviour. Thanks for sharing the information!

        Kind regards,

        ~Jakub

        Show
        Jakub Podlesak added a comment - Hi Øyvind, Thanks for the clarification. I am then going to resolve this as won't fix. Others will still have a chance to see how to workaround if they also experience above described behaviour. Thanks for sharing the information! Kind regards, ~Jakub
        Hide
        Jakub Podlesak added a comment -

        Resolving as won't fix. Øyvind, the original reporter, is fine with his current setup, and the issue was IIUC mainly reported
        to share the workaround with other users.

        Show
        Jakub Podlesak added a comment - Resolving as won't fix. Øyvind, the original reporter, is fine with his current setup, and the issue was IIUC mainly reported to share the workaround with other users.

          People

          • Assignee:
            Jakub Podlesak
            Reporter:
            VingeF
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: