Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think, solution number 4 is OK. It is simple to understand and clear.</p> <p>I propose similar solution in which we can use <a href="http://www.cowtowncoder.com/blog/archives/2011/07/entry_458.html" rel="noreferrer">@JsonAnySetter</a> annotation. Please, see below example:</p> <pre><code>import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.databind.ObjectMapper; public class JacksonProgram { public static void main(String[] args) throws Exception { C1 c1 = new C1(); c1.setProp1("a"); c1.setProp3("c"); User user = new User(); user.setName("Tom"); user.setSurname("Irg"); ObjectMapper mapper = new ObjectMapper(); System.out.println(mapper.convertValue(c1, UriFormat.class)); System.out.println(mapper.convertValue(user, UriFormat.class)); } } class UriFormat { private StringBuilder builder = new StringBuilder(); @JsonAnySetter public void addToUri(String name, Object property) { if (builder.length() &gt; 0) { builder.append("&amp;"); } builder.append(name).append("=").append(property); } @Override public String toString() { return builder.toString(); } } </code></pre> <p>Above program prints:</p> <pre><code>prop1=a&amp;prop2=null&amp;prop3=c name=Tom&amp;surname=Irg </code></pre> <p>And your getRequest method could look like this:</p> <pre><code>public String getRequest(String url, Object obj) { String serializedUri = mapper.convertValue(obj, UriFormat.class).toString(); String response = restTemplate.getForObject(url + "?" + serializedUri, String.class); return response; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload