Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery ajax/post - setting JSON in the data field causes JsonMappingException
    primarykey
    data
    text
    <p>I am having issues sending a JQuery post to my server. I have narrowed the problem down to the data field not being set correctly in my javascript, which leads to an exception: </p> <blockquote> <p>org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of com.myserver.rest.messages.dto.NewMessageDTO out of START_ARRAY token</p> </blockquote> <p>The code that <strong>works</strong>, but not very clean:</p> <pre><code> $.ajax({ type: "POST", url: "../resources/messages/", data: '{"subject": "' + subject + '", "message": "' + message + '", "messageType": "' + type + '", "employeeIDs": [' + employeeIDs + '], "assignmentIDs": [' + assignmentIDs +']}', contentType: "application/json", success: successHandler, error: defaultErrorHandler }); </code></pre> <p>Which renders to:</p> <blockquote> <p>{"subject": "test", "message": "test", "messageType": "MESSAGE", "employeeIDs": [461,485], "assignmentIDs": [103]}</p> </blockquote> <p>The code that <strong>does not work</strong>, but is cleaner:</p> <pre><code> $.ajax({ type: "POST", url: "../resources/messages/", data: {'subject': subject, 'message': message, 'messageType': type, 'employeeIDs[]': employeeIDs, 'assignmentIDs[]': assignmentIDs}, contentType: "application/json", success: successHandler, error: defaultErrorHandler }); </code></pre> <p>Which is rendering as application/x-www-form-urlencoded for some reason:</p> <blockquote> <p>subject=test&amp;message=test&amp;messageType=MESSAGE&amp;employeeIDs%5B%5D=461&amp;employeeIDs%5B%5D=485&amp;assignmentIDs%5B%5D=103</p> </blockquote> <p>Any ideas what I am doing wrong here? Thanks in advance for any help</p>
    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. 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