title: Could Spring decode @ModelAttribute if it contains Long field or is a Map instance?
body: <p>Is any other way than <code>@SessionAttributes(&quot;entitytopass&quot;)</code> to pass java object:</p>
  <p>from POST method of &quot;form&quot; servlet / controller -&gt;</p>
  <p>-&gt; to the &quot;display&quot; one,</p>
  <p>if it contains Long field or is Map instance?</p>
  <p>After many attempts, using <code>RedirectAttributes redirectAttributes</code> to pass <code>Entity entity</code>, ex:</p>
  <pre><code>  redirectAttributes.addAttribute(&quot;entitytopass&quot;, entity);
  </code></pre>
  <p>I was surprised to find that it persistently parses the field from Long to Integer one. This results in a failure to build the received object in the receiving servlet. So, method as below is not successful and throws <code>TypeMismatchException</code> :</p>
  <pre><code>@RequestMapping(value =&quot;/display&quot;, method = RequestMethod.GET)  
   public String add(@ModelAttribute(&quot;entitytopass&quot;) Entity entityreceived, Model model) {  
      model.addAttribute(&quot;entitypresented&quot;, entityreceived);
    return &quot;/displaypage&quot;;  // displaypage.jsp would present saved values  
   }   
  </code></pre>
  <p>Spring Error report after <code>Entity entityreceived</code> decoding would be:</p>
  <pre><code>Failed to convert value of type 'java.lang.String' to required type 'some.domain.jpa.model.Entity'; 
  nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.ModelAttribute some.domain.jpa.model.Entity] for value '0'; 
  nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Provided id of the wrong type for class some.domain.jpa.model.Entity. Expected: class java.lang.Long, got class java.lang.Integer; 
  nested exception is java.lang.IllegalArgumentException: Provided id of the wrong type for class some.domain.jpa.model.Entity. Expected: class java.lang.Long, got class java.lang.Integer 
  </code></pre>
  <p>the same happans if entity would be <code>Map&lt;String,String&gt;</code> instance, although the objects transferred and extracted from the session are encoded and decoded without any problem beetween servlets / controllers.</p>
  <p>-- edit --</p>
  <p>Entity is symbolic, but ex.</p>
  <pre><code>public class Entity extends BaseEntity implements Serializable, EntityLabels {
      private static final long serialVersionUID = -3776095967033917869L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = &quot;addr_id&quot;)
      private long addressId;
  
      @Column(updatable = true, name = &quot;addr_name&quot;, nullable = true, length = 50)
      private String addressName;
  
      @Column(updatable = true, name = &quot;city&quot;, nullable = false, length = 50)
      private String city;
  
      @Column(updatable = true, name = &quot;post_cod&quot;, nullable = false, length = 6)
      private String postalCode;
  
      @Column(updatable = true, name = &quot;street&quot;, nullable = false, length = 50)
      private String streetName;
  
      @Column(updatable = true, name = &quot;str_no&quot;, nullable = false, length = 6)
      private String streetNumber;
  
      @Column(updatable = true, name = &quot;flat_no&quot;, nullable = true, length = 6)
      private String flatNumber;
  
      @ColumnDefault(value = &quot;'Poland'&quot;)
      @Column(updatable = true, name = &quot;country&quot;, nullable = false, length = 50)
      private String country; // = &quot;Poland&quot;;
  
      // standard constructor
      public Entity() {
      }
  
      // getters &amp; setters
  
  }   
  </code></pre>