2

I have created a rest Service using Apache Camel Swagger component. The rest service works fine but the request and response schema is not what i intended of.

The schema that i am trying to create is :

 {
  "GetStudentData": [
    {
      "RollNumber": "1",
      "Name": "ABC",
      "ClassName": "VII",
      "Grade": "A"
    }]
}

For this i have created a model as:

    import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "GetStudentData")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="", propOrder={"studentInfo"})
public class StudentInfoWrapper {
    @XmlElement(required=true)
    private List<Student> studentInfo;
    private double visiteddate;

    public double getVisiteddate() {
        return visiteddate;
    }
    public void setVisiteddate(double visiteddate) {
        this.visiteddate = visiteddate;
    }
    public List<Student> getStudentInfo() {
        return studentInfo;
    }
    public void setStudentInfo(List<Student> studentInfo) {
        studentInfo = studentInfo;
    }
}

And my student class is:

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="", propOrder={"RollNumber", "Name", "ClassName", "Grade"})
public class Student {
    private String RollNumber;
    private String Name;
    private String ClassName;
    private String Grade;

    public String getRollNumber() {
        return RollNumber;
    }
    public void setRollNumber(String rollNumber) {
        RollNumber = rollNumber;
    }

    public String getName() {
        return Name;
    }
    public void setName(String name) {
        Name = name;
    }

    public String getClassName() {
        return ClassName;
    }
    public void setClassName(String className) {
        ClassName = className;
    }

    public String getGrade() {
        return Grade;
    }
    public void setGrade(String grade) {
        Grade = grade;
    }
}

So when i load the above service into the swaggerUI it doesn't show the schema that i want.

How can i i get the desired schema. Looking forward to your answers. Thanks in advance.

Roy
  • 1,231
  • 1
  • 24
  • 61
  • Can you show the generated schema you get? – Claus Ibsen Apr 01 '16 at 10:59
  • { "studentList": [ { "RollNumber": "1", "Name": "ABC", "ClassName": "VII", "Grade": "A" }] } This is the input Schema that i can see in Swagger UI.. – Roy Apr 04 '16 at 04:56
  • I just wanted to know that how can i enable the ObjectMapper Serialize feature Wrap Root.. in the above context. – Roy Apr 14 '16 at 09:54
  • See the documentation at http://camel.apache.org/rest-dsl about enabling/disabling jackson features – Claus Ibsen Apr 14 '16 at 13:09
  • Thanks for the reply Ibsen.. Can you give an example for enabling/disabling the feature.. – Roy Apr 18 '16 at 03:52
  • I have added a enable feature inside rest configuration as but its not working.. Am i doing right? – Roy Apr 18 '16 at 04:04

0 Answers0