Skip to content

Play2/scala: A property named "is_persistent" gets shortened in the json to "_persistent" #415

Closed

Description

@kieranbenton

As the subject line says - other properties that contain _'s work correctly?

Activity

  1. fehguy commented on Jan 20, 2014

    @fehguy
    Contributor

    Hi, this is due to this logic:

    https://github.com/wordnik/swagger-core/blob/develop/modules/swagger-core/src/main/scala/com/wordnik/swagger/converter/ModelPropertyParser.scala#L73

      def extractGetterProperty(methodFieldName: String): (String, Boolean) = {
        if (methodFieldName != null &&
          (methodFieldName.startsWith("get")) &&
          methodFieldName.length > 3) {
          (methodFieldName.substring(3, 4).toLowerCase() + methodFieldName.substring(4, methodFieldName.length()), true)
        } else if (methodFieldName != null &&
          (methodFieldName.startsWith("is")) &&
          methodFieldName.length > 2) {
          (methodFieldName.substring(2, 3).toLowerCase() + methodFieldName.substring(3, methodFieldName.length()), true)
        } else {
          (methodFieldName, false)
        }
      }

    Looking at alternatives to just detecting "is_"

  2. kieranbenton commented on Jan 21, 2014

    @kieranbenton
    Author

    Under what circumstances are you trying to strip the 'is' off? I can't find
    any reference to when Scala might automatically add that prefix?

    Cheers.

    On 20 January 2014 18:52, Tony Tam [email protected] wrote:

    Hi, this is due to this logic:

    https://github.com/wordnik/swagger-core/blob/develop/modules/swagger-core/src/main/scala/com/wordnik/swagger/converter/ModelPropertyParser.scala#L73

    def extractGetterProperty(methodFieldName: String): (String, Boolean) = {
    if (methodFieldName != null &&
    (methodFieldName.startsWith("get")) &&
    methodFieldName.length > 3) {
    (methodFieldName.substring(3, 4).toLowerCase() + methodFieldName.substring(4, methodFieldName.length()), true)
    } else if (methodFieldName != null &&
    (methodFieldName.startsWith("is")) &&
    methodFieldName.length > 2) {
    (methodFieldName.substring(2, 3).toLowerCase() + methodFieldName.substring(3, methodFieldName.length()), true)
    } else {
    (methodFieldName, false)
    }
    }

    Looking at alternatives to just detecting "is_"

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/415#issuecomment-32786394
    .

  3. mkantor commented on Mar 20, 2014

    @mkantor

    We just got bit by this today. Our application didn't know that it needed to convert "is*" parameters in order to be consistent with the generated spec.

    Is this documented somewhere? Any other automatic conversions that we should be aware of besides "is_" and "get_"?

  4. fehguy commented on Apr 8, 2014

    @fehguy
    Contributor

    is/has (boolean), get/set (other) are typical for POJOs, and are used to determine a property name (getFoo => foo, isFoo => foo, etc.) is_, has_ can have special treatment. To be clear, you're looking to see that is_* is preserved?

  5. mkantor commented on Aug 9, 2014

    @mkantor

    The way it's written, even properties with names like "isometric" get mangled. This definitely isn't desirable behavior.

  6. modified the milestone: on Sep 19, 2014
  7. modified the milestones: v1.5.0-M1, on Dec 20, 2014
  8. fehguy commented on Jan 10, 2015

    @fehguy
    Contributor

    Looks like this is an issue with both the internal (1.3.x) introspection and jackson as well (1.5.x). Since the focus is on 1.5.x right now, I'm looking into a solution.

    The Jackson BeanDescription method findProperties() is taking public property names like such:

    is_persistent
    gettersAndHaters

    and mangling them to _persistent and tersAndHaters

    I could use some help from @cowtowncoder on this one:

    https://github.com/swagger-api/swagger-core/blob/develop_2.0/modules/swagger-core/src/main/java/com/wordnik/swagger/jackson/ModelResolver.java#L172

        for (BeanPropertyDefinition propDef : beanDesc.findProperties()) {
          Property property = null;
          String propName = propDef.getName();

    Where the properties in this test class:

    https://github.com/swagger-api/swagger-core/blob/develop_2.0/modules/swagger-core/src/test/scala/models/ModelPropertyName.java

    public class ModelPropertyName {
      public boolean is_persistent() { return true; }
      public String isometric() { return null; }
      public String gettersAndHaters() { return null; }
    }

    emerge mangled

  9. cowtowncoder commented on Jan 10, 2015

    @cowtowncoder

    Right: isXxx methods are auto-detected if enabled by visibility (separately controlled as "is-getters", distinct from "regular" getters) AND return type is boolean or Boolean.
    If detected, name mangling is identical to get methods.

    Jackson 2.5 has a new MapperFeature, USE_STD_BEAN_NAMING: http://fasterxml.github.io/jackson-databind/javadoc/2.5/com/fasterxml/jackson/databind/MapperFeature.html#USE_STD_BEAN_NAMING
    which can be enabled to change it slightly (earlier getURL results in Url; with STD_BEAN_NAMING_ENABLED, remains URL), but I don't think it'd have effect here.

    If the goal is NOT to detect these methods, it is easy enough to change by changing visibility levels.
    One way is with @JsonAutoDetect; another with ObjectMapper.setVisibility(), which can either:

    • Change level for specific kind of accessor (setter, getter, field, is-getter, constructor), or
    • Use a fully custom VisibilityChecker

    There is no simple overridability wrt name mangling (to perhaps avoid "is_persistent", when naming scheme would expect camel-case), although it might be possible to find overrides that work there.

    So the question is just what is the desired behavior.

  10. fehguy commented on Jan 10, 2015

    @fehguy
    Contributor

    Thanks, any way to detect as "getXxx" as a getter and not treat "getxxx" as a getter? Likewise "isXxx" is a getter but "isxxx" or "is_xxx" is not

  11. 2 remaining items

  12. added a commit that references this issue on Jan 10, 2015
  13. fehguy commented on Jan 10, 2015

    @fehguy
    Contributor

    It's a hack but it works:

    d183d8c

    Required get to be followed by an uppercase or uses original field name. Same behavior for is.

  14. modified the milestones: v1.3.13, v1.5.0-M1 on Jan 12, 2015
  15. dmn1899 commented on Feb 7, 2017

    @dmn1899

    Hi guys
    your decision is not clear correct
    there are correct getters and setters with lower case after 'get', for example for property 'aName' getter will be named 'getaName'. intellij idea generates it and considers it is valid

    your check
    !Character.isUpperCase(altName.charAt(offset)
    should replace with
    !Character.isUpperCase(offset) && !Character.isLowerCase(offset)

    special simbols ('_' for example) is not upper or lower case

    best regards, hope you will fix it

  16. webron commented on Feb 7, 2017

    @webron
    Contributor

    @dmn1899 commenting on an issue that was closed over two years ago is not the way to do it. If you experience an issue with the latest version, consider submitting a new ticket with the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions