java - How to send JSON as a parameter in url using Spring RestTemplate? -


i trying achieve same thing this: how use query parameter represented json spring resttemplate?, sending json string url parameter in resttemplate.exchange().

the accepted answer mentions sending json object request parameter not idea since face problem curly brackets inside json. happening when trying make call api. since api system, cannot ask them change format , have call endpoint, passing json parameter. how can achieve in resttemplate.exchange() call?

note: mentioned related question not guide on how overcome problem , not have enough reputation comment on ask author of answer.

answering own question. while bad idea pass json in query/url parameter, there workaround suggested here: https://jira.spring.io/browse/spr-9220?focusedcommentid=76760&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-76760.
replicating code here in case link goes dead:

string url = "http://localhost:8983/solr/select?wt=json&indent=true&fl=*&q=*:*&fq={!geofilt}&sfield=venue_location&pt=28.0674,-80.5595&d=25"; uri uri = uricomponentsbuilder.fromuristring(url).build().encode().touri();  system.out.println(uri); // http://localhost:8983/solr/select?wt=json&indent=true&fl=*&q=*:*&fq=%7b!geofilt%7d&sfield=venue_location&pt=28.0674,-80.5595&d=25 

basically, instead of passing url having json query/url parameters string, pass uri. call exchange method before, uri instead of string:

resttemplate.exchange(uri, httpmethod.get, requestentity, string.class) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -