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

@JsonProperty("newName") is not respected on fields #486

Closed
shuz opened this issue Mar 14, 2014 · 1 comment
Closed

@JsonProperty("newName") is not respected on fields #486

shuz opened this issue Mar 14, 2014 · 1 comment

Comments

@shuz
Copy link
Contributor

shuz commented Mar 14, 2014

public class User {

    @JsonProperty("userId")
    private Integer id;

    public Integer getId() { return id; }
    public void setId(Integer id) { this.id = id; }
    ...
}

The field is not renamed in the swagger doc.

In com/wordnik/swagger/converter/ModelPropertyParser.scala

    try {
      val fieldAnnotations = getDeclaredField(this.cls, name).getAnnotations()
      var propAnnoOutput = processAnnotations(name, fieldAnnotations)
      var propPosition = propAnnoOutput("position").asInstanceOf[Int]

The propAnnoOutput from the field is not used to update the name.

@shuz
Copy link
Contributor Author

shuz commented Mar 14, 2014

The work around:

diff --git a/modules/swagger-core/src/main/scala/com/wordnik/swagger/converter/ModelPropertyParser.scala b/modules/swagger-core/src/main/scala/com/wordnik/swagger/converter/ModelPropertyParser.scala
index 30b7bab..9d183ec 100644
--- a/modules/swagger-core/src/main/scala/com/wordnik/swagger/converter/ModelPropertyParser.scala
+++ b/modules/swagger-core/src/main/scala/com/wordnik/swagger/converter/ModelPropertyParser.scala
@@ -92 +91,0 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
-    if (name == null) name = originalName
@@ -113,2 +112,3 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
-      val fieldAnnotations = getDeclaredField(this.cls, name).getAnnotations()
-      var propAnnoOutput = processAnnotations(name, fieldAnnotations)
+      val fieldAnnotations = getDeclaredField(this.cls, originalName).getAnnotations()
+
+      var propAnnoOutput = processAnnotations(originalName, fieldAnnotations)
@@ -116,0 +117,3 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
+      if (name == null || name.equals(originalName)) {
+        name = propAnnoOutput("name").asInstanceOf[String]
+      }
@@ -133,0 +137,2 @@ class ModelPropertyParser(cls: Class[_], t: Map[String, String] = Map.empty) (im
+    if (name == null) name = originalName
+

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

No branches or pull requests

2 participants