Answer the question
In order to leave comments, you need to log in
How to make a web service that accepts an abstract JSON object in which there will be a regular list?
I have a web service in Spring, it must accept a JSON object in which there will be a regular list with which I need to work further. The difficulty arose with the fact that I don’t understand how I can get some kind of abstract JSON object and not from a specific site ... I used to write a similar web service that also received a JSON sheet object, but from a specific site! And I don’t understand how to make a web service that receives an abstract JSON. Tell me please.
An example of how I implemented a service to get a JSON object from a specific site.
HttpClient httpClient = HttpClientBuilder.create().build();
ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
private RestTemplate restTemplate = new RestTemplate(requestFactory);
public List<SiteObj> getSites() {
String webSiteUrl = "https://api.stackexchange.com/2.2/sites?page=1&pagesize=999&filter=!FmdZfVGXZN9h5PtNfuvm(ASXcf";
SitesDTO response = null;
try {
response = restTemplate.getForObject(new URI(webSiteUrl), SitesDTO.class);
} catch (URISyntaxException e) {
e.printStackTrace();
}
return response.getItems();
}
}
Answer the question
In order to leave comments, you need to log in
Your code itself reads data from another site. And you need a service that will receive data from outside.
Something like
@RestController
@RequestMapping(produces = APPLICATION_JSON_UTF8_VALUE)
public class MyController {
@PostMapping("process-json")
@ResponseBody
public ResponseEntity<String> processJson(@RequestParam(value = "stringArray")List<String> stringArray) {
return process(stringArray);
}
}
"Create a web service that
accepts a json object in the form of an array of strings. The array check is initialized by a REST API call, in the input parameters of which an array of strings is passed (the data transfer format is
JSON). "
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question