jax rs - how to see actual body sent from restassured -


i have created jax-rs rest api , tested rest-assured. tests green. trying create html/js front end it.

my problem not know how json objects should accepted rest api. restassured/jax-rs never handled request strings. fill in objects , objects, (un)marshaling (json) invisible.

is there way can see (debug) strings created rest-assured/java , sent on "wire"?

i'm not restassured used, can't answer question directly, here ideas may out.

  • i don't know serializer restassured uses under hood, resteasy on wildfly uses jackson default. familiar library. less trivial application, may need dig apis directly desired results. here it's documentation. particular case can simple as

    objectmapper mapper = new objectmapper(); string jsonstring = mapper.writevalueasstring(yourobject); system.out.println(jsonstring); 

    this print out pojo in json format, based on getters in class. @ basic level. if don't have jackson dependency, can add

    <dependency>     <groupid>com.fasterxml.jackson.core</groupid>     <artifactid>jackson-databind</artifactid>     <version>2.4.0</version> </dependency> 
  • a friend (tool) have curl. it's command line tool allows make rest/http (other protocols also) requests. though particular case wouldn't help, send request 1 resources serves same type accepted in post. way, can see resulting json. may little @ point, tool if you're going doing lot of rest development.

  • you might want check out browser tool [postman chrome]

  • you should familiar json format. once familiar it, , start working json framework, you'll notice @ basic level, work similarly.

    java object == json object ( {} ) java collection/array == json array ( [] ) java fields/properties == json keys  getters used keys , values (for serialization) setters used deserialization 

    so example have class

    public class person {     string name;     list<person> friends;      public string getname() { return name; }     public void setname(string name) { return name; }     // getter , setter friends } 

    an instance of person produce following json

    {     "name" : "peeskillet",     "friends": [         {             "name": "lebron james"         },         {             "name": "steph curry"         }     ] } 

it's pretty simple once hang of it.

as far working javascript, there json.stringify(javascriptobject) serialize javacript objects json strings. generally, can model javascript object java objects.

hope helped.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -