0

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?

Stone
  • 2,912
  • 1
  • 21
  • 18
  • Why `Vector`? Why not a simple `List` or even a `Collection`? – fge Apr 01 '14 at 10:10
  • @fge: i'm getting the same result with `List` or a `Array` – Stone Apr 01 '14 at 10:13
  • Then use a `List`. `Vector` is obsolete. – fge Apr 01 '14 at 10:14
  • i'm getting the same wrong result. – Stone Apr 01 '14 at 10:17
  • I know this doesn't solve your problem, but this is 2014 and you shouldn't use `Vector` -- anyway, I suspect the problem is with `@XmlRootElement`; do you really need it? – fge Apr 01 '14 at 10:22
  • ok. now i get this Exception `A message body writer for Java class java.util.ArrayList, and Java type java.util.Collection, and MIME media type application/json was not found.` – Stone Apr 01 '14 at 10:24
  • This looks familiar, a lot of questions have been asked about that already. Try and search the site with relevant keywords and I believe you can find your solution – fge Apr 01 '14 at 10:26
  • solved it by using the first answer there [http://stackoverflow.com/questions/13108161/a-message-body-writer-for-java-class-not-found](http://stackoverflow.com/questions/13108161/a-message-body-writer-for-java-class-not-found) – Stone Apr 01 '14 at 10:34

1 Answers1

0

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>
Stone
  • 2,912
  • 1
  • 21
  • 18