Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I post object as JSON for adding from Jax RS Client to server
    primarykey
    data
    text
    <p>I try to learn rest webservice in java. I wrote a server jboss. I can get a list from server but I can't post a object to server. I try to post with restclient. This is successful. First block is get, second block is post and final block is request from client. Client project is normal java project. It is not web, jboss or it has not like jackson lib. How can I post object as JSON for adding from Jax RS Client to server?</p> <pre><code>@GET @Path("/categories") @Produces(MediaType.APPLICATION_JSON) public List&lt;CategoryVO&gt; getAllCategories(){ List&lt;Category&gt; cats = entityManager.createQuery("select c from Category c").getResultList(); ArrayList&lt;CategoryVO&gt; results = new ArrayList&lt;CategoryVO&gt;(); for (Category c : cats) { results.add(new CategoryVO(c.getTitle(), c.getId())); } return results; } @POST @Path("/categoryAdd") @Consumes(MediaType.APPLICATION_JSON) public void saveCategory(CategoryVO catVO){ System.out.println("Save Method is running"); Category cat = new Category(catVO.getTitle()); entityManager.persist(cat); } public static void main(String[] args) { URL url = null; HttpURLConnection con; try { url = new URL( "http://localhost:8080/RestWS/rest/NetasRestWS/categories"); con = (HttpURLConnection) url.openConnection(); InputStreamReader reader = new InputStreamReader( con.getInputStream()); while(true){ int x =reader.read(); if(x==-1) break; System.out.print((char)x); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload