Réponse avec un JSON imbriqué

Nous pouvons avoir une réponse avec un JSON imbriqué.

Pour une description comme ceci :

{  
  "weather": { +  
    "wind": { +  
    "speed": 15.3, +  
    "direction": 287.0 +  
   },  
  "temperature": {  
    "high": 21.2,  
    "low": 14.8  
    }  
  }  
} 

Nous pouvons avoir ce code :

this.mockMvc.perform(get("/locations/1").accept(MediaType. 
APPLICATION_JSON)) +  
.andExpect(status().isOk()).andDo(document("location", +  
responseBody(beneathPath("weather.temperature"))));  
 
Identifieur : beneath-$\{path}.  
 
Snippet : response-description-beneath-weather.temperature.adoc   

Code :  

responseBody(beneathPath("weather.temperature")
.withSubsectionId("temp"));  

Documentation des champs :  

this.mockMvc.perform(get("/locations/1").accept(MediaType.  
APPLICATION_JSON)) +  
.andExpect(status().isOk()) +  
.andDo(document("location", +  
responseFields(beneathPath("weather.temperature"), +  
fieldWithPath("high").description( +  
"The forecast high in degrees celcius"), +  
fieldWithPath("low") +  
.description("The forecast...
couv_EP4JASP.png

Découvrez 

le livre :

Aussi inclus dans nos :

Précédent
Requête et réponse
Suivant
Personnalisation de la documentation