Reputation: 11
I have a little problem here and need me some opinions.
Here is a peace of code
@XmlRootElement
public abstract class Article {
// quert params and name of xml elements
private String name;
private String author;
private String description;
private String picture_url;
private double price;
private int id;
public Article() {
}
public Article(String name, String author, String description, String picture_url, double price, int id) {
super();
this.name = name;
this.author = author;
this.description = description;
this.picture_url = picture_url;
this.price = price;
this.id = id;
}
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
public String getDescription() {
return description;
}
public String getPicture_url() {
return picture_url;
}
public double getPrice() {
return price;
}
public int getId() {
return id;
}
}
And also i have class CD that extend Article. The problem is when i try to create a new Article with POST request in REST application is thrown me exception every time but i provide the no arg constructor also in CD class? What is the catch here ?
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/articles")
public List<Article> gellAllItems(){
return new ArrayList<>(repo.get().values());
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/articles/{articleId}")
public Article get(@PathParam("articleId") int id) {
return repo.get(id);
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/articles")
public Article create(Article article) { // return a specific response with entity
repo.create(article);
return article;
}
Upvotes: 0
Views: 47
Reputation: 1057
Your class is abstract
. It cannot be instantiated. Remove the abstract and it should work.
Upvotes: 3