title: POJO to MultiValueMap mapping/binding/conversion in spring 3
body: <p>I have a POJO I need to format as a MultiValueMap.  This MultiValueMap will be used as the request in a POST method using the restTemplate class and will be passed along to my web service as contentType application/x-www-form-urlencoded.  </p>
  
  <p>Are there any tools or utilities that will do the POJO -> MultiValueMap conversion for me?</p>
  
  <p>sample pojo:</p>
  
  <pre><code>public class SampleDto implements Serializable, Idable, Comparable&lt;SampleDto&gt; {
  
      private static final long serialVersionUID = 1L;
  
      private Integer id;
  
      private Boolean active;
  
      private String lastName;
  
      private List&lt;SurgeonClinicDto&gt; surgeonClinics = new ArrayList&lt;SurgeonClinicDto&gt;();
      private List&lt;PromptValueDto&gt; promptValues = new ArrayList&lt;PromptValueDto&gt;();
  
      private Date lastUpdated = new Date();
  
      public SampleDto() {
  
      }
  
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public Boolean getActive() {
          return active;
      }
  
      public void setActive(Boolean active) {
          this.active = active;
      }
  
      public String getLastName() {
          return lastName;
      }
  
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      public Date getLastUpdated() {
          return lastUpdated;
      }
  
      public void setLastUpdated(Date lastUpdated) {
          this.lastUpdated = lastUpdated;
      }
  
      public List&lt;SurgeonClinicDto&gt; getSurgeonClinics() {
          return surgeonClinics;
      }
  
      public void setSurgeonClinics(List&lt;SurgeonClinicDto&gt; surgeonClinics) {
          this.surgeonClinics = surgeonClinics;
      }
  
      public List&lt;PromptValueDto&gt; getPromptValues() {
          return promptValues;
      }
  
      public void setPromptValues(List&lt;PromptValueDto&gt; promptValues) {
          this.promptValues = promptValues;
      }
  
      public int compareTo(SampleDto o) {
  
          if (getLastName() != null &amp;&amp; o.getLastName() != null
                  &amp;&amp; getLastName().compareTo(o.getLastName()) != 0) {
              return getLastName().compareTo(o.getLastName());
          }
          if (getActive() != null &amp;&amp; o.getActive() != null
                  &amp;&amp; getActive().compareTo(o.getActive()) != 0) {
              return getActive().compareTo(o.getActive());
          }
          if (getLastUpdated() != null &amp;&amp; o.getLastUpdated() != null
                  &amp;&amp; getLastUpdated().compareTo(o.getLastUpdated()) != 0) {
              return getLastUpdated().compareTo(o.getLastUpdated());
          }
          if (getId() != null &amp;&amp; o.getId() != null
                  &amp;&amp; getId().compareTo(o.getId()) != 0) {
              return getId().compareTo(o.getId());
          }
  
          return 0;
      }
  }
  </code></pre>
  
  <p>After MultiValueMap is converted to contentType: application/x-www-form-urlencoded by calling POST on restTemplate object:</p>
  
  <pre><code>id=11752&amp;active=true&amp;lastName=Brownie&amp;
  promptValues[0].id=12&amp;promptValues[0].miscPromptId=882&amp;promptValues[0].value=meFirst&amp;
  promptValues[1].id=13&amp;promptValues[1].miscPromptId=881&amp;promptValues[1].value=youToo&amp;
  surgeonClinics[0].address1=newAddress&amp;surgeonClinics[0].address2=newAddress2&amp;surgeonClinics[0].city=clinic City&amp;
  surgeonClinics[0].email=email@clinic1.com&amp;surgeonClinics[0].fax=123.456.7890&amp;surgeonClinics[0].id=33273&amp;
  surgeonClinics[0].name=clinic name&amp;surgeonClinics[0].phone=890-098-4567&amp;
  surgeonClinics[0].zip=34567&amp;surgeonClinics[0].surgeryCenter1=MySurgeryCenter1&amp;
  surgeonClinics[0].surgeryCenter2=MySurgeryCenter2&amp;
  surgeonClinics[1].address1=newAddress11&amp;surgeonClinics[1].address2=newAddress22&amp;surgeonClinics[1].city=clinic2 City&amp;
  surgeonClinics[1].email=email@clinic2.com&amp;surgeonClinics[1].fax=123.456.7890&amp;surgeonClinics[1].id=33274&amp;
  surgeonClinics[1].name=clinic2 name&amp;surgeonClinics[1].phone=890-098-4567&amp;
  surgeonClinics[1].zip=34567&amp;
  surgeonClinics[1].surgeryCenter1=MySurgeryCenter21&amp;surgeonClinics[1].surgeryCenter2=MySurgeryCenter22
  </code></pre>