1 Reply Latest reply on Feb 19, 2013 3:40 AM by pr0st

    Resteasy: Object to JSON upper case?

    pr0st

      Hi Guys,

      I am pretty new to Resteasy and everything that belongs to it and I

      have a tiny problem that sounds actually pretty easy to fix but I was not able to...

      I have a JavaScript library which is expecting a capitalized JSON node.

      Unfortunately I am not able to make any changes in that library so I need to

      figure out a way, to fix this problem in the java part. I don't have anything fancy,

      just 2 classes like this:

       

      public class Body {
      
        private String def;
        private List<Employee> employees;
      
        public String getDef() {
      
          return def;
        }
      
        public void setDef(String def) {
      
          this.def = def;
        }
      
        public List<Employee> getItems() {
      
          return employees;
        }
      
        public void setItems(List<Employee> items) {
      
          employees = items;
        }
      
      }
      

       

      and

       

      public class Employee {
      
        private String name;
      
        public String getName() {
      
          return name;
        }
      
        public void setName(String name) {
      
          this.name = name;
        }
      
      }
      

       

      The final JSON Code looks like this:

      {"body":{"def":"Task","items":[{"name":"Test Name"}]}}

       

      but I want it to look like this:

      {"Body":{"Def":"Task","Items":[{"name":"Test Name"}]}}

       

      Is there any way to handle this problem? Any annotation for renaming the nodes maybe?

       

      Regards and thanks in advance

        • 1. Re: Resteasy: Object to JSON upper case?
          pr0st

          Found the answer ...

          Added this to our pom:

          <dependency>
              <groupId>org.codehaus.jackson</groupId>
          <artifactId>jackson-core-asl</artifactId>
              <version>1.9.2</version>
              <scope>provided</scope>
          </dependency>

           

          and then used:

          @JsonTypeName("Body") and @JsonProperty("Def")

          in the class files!