Forum Stats

  • 3,875,517 Users
  • 2,266,938 Discussions


Accepting json object not working

Jack_Tauson_Sr Member Posts: 1
edited Mar 13, 2018 1:23PM in Java Programming

I am following an online example to test a POST request by passing a JSON object using Postman client as shown below. :

    package com.thejavageek.jaxrs;       import;    import;       @ApplicationPath("/rest")    public class ExampleApplication extends Application {       }

    package com.thejavageek.jaxrs;       import;    import;    import;    import;       import com.thejavageek.jaxrs.model.Person;       @Path("/HelloWorld")    public class HelloWorldService {       @POST    @Path("/writePersonToDB")    @Consumes(MediaType.APPLICATION_JSON)    public void writePersonToDB(Person person) {       System.out.println(person);       }       }

    package com.thejavageek.jaxrs.model;       public class Person {       private String name;    private String surname;    private String address;       public String getName() {    return name;    }       public void setName(String name) { = name;    }       public String getSurname() {    return surname;    }       public void setSurname(String surname) {    this.surname = surname;    }       public String getAddress() {    return address;    }       public void setAddress(String address) {    this.address = address;    }       @Override    public String toString() {    return "Person [name=" + name + ", surname=" + surname + ", address=" + address + "]";    }       }

Error in Postman :


I have tested another HelloWorld example of GET request from here and it worked fine. So there isn't any eclipse related issue on my local host/browser.



  • handat
    handat Member Posts: 4,688 Gold Crown
    edited Mar 13, 2018 2:26AM

    You failed to mention what the project name was that you deployed your application as. From your postman screenshot, one would assume that it was JAX-RS_PostExamples, but you should double check what it really is as it needs to match what you put into postman.

  • Unknown
    edited Mar 13, 2018 1:20PM

    And that is NOT the project name in the example at the link posted.

    That project name was JAX-RS_examples

  • Unknown
    edited Mar 13, 2018 1:23PM

    You clearly did NOT follow that example exactly because it says to do this:

    Deploy the web app in jboss server and open chrome rest client. and send request as below. URL: http://localhost:8080/JAX-RS_examples/rest/HelloWorld/writePersonToDB

    That is NOT the project name in your code.

    Did you 'Deploy the web app in jboss server'?

    Did you 'open chrome rest client'?

    Assuming the example at the link actually works the error you got indicates there is no such project/jar/file/code at the location where the server is looking.

    Not a Java issue - a deployment issue.

This discussion has been closed.