سؤال

i am returning a Vector with the Object FLineType

The Return Methode looks like

@GET
@Path("/linetypes")
@Produces(MediaType.APPLICATION_JSON)
public Vector<FLineType> getLineTypes(){
    db = Database.getInstance();
    return db.getLineTypes();
}

FLineType looks like

    import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class FLineType {
    private int id;
    private String bez;

public FLineType(){}

public FLineType(int id, String bez) {
    super();
    this.id = id;
    this.bez = bez;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getBez() {
    return bez;
}

public void setBez(String bez) {
    this.bez = bez;
}

}

and i receive data looking like

{"fLineType":[{"bez":"Linie 1","id":"1"},{"bez":"Linie 2","id":"2"},{"bez":"Linie 3","id":"3"},{"bez":"Powerplay 1","id":"4"},{"bez":"Powerplay 2","id":"5"},{"bez":"Unterzahl 1","id":"6"},{"bez":"Unterzahl 2","id":"7"}]}

but i want only the JSON Array data in the [] brackets. without the Object Name. because i get the JSONException that the Data must start with [ when receiving.

i am using jersey 1.18 for the REST Server.

can anybody help me?

هل كانت مفيدة؟

المحلول

i solved it by adding these lines to my web.xml file.

<init-param>
  <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
  <param-value>true</param-value>
</init-param>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top