Announcement Announcement Module
Collapse
No announcement yet.
Spring & JQuery Nested Object Formatting $.post Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring & JQuery Nested Object Formatting $.post

    I was digging into something interesting I saw...JQuery likes to format parameters using [] instead of .

    Has anyone written a filter/request wrapper/something to handle this?



    Take this example, you want to post the following to the server.
    {"name":"test","address":[{"city":"one","state":"a"},{"city":"two","state":" b"}]}

    Send it as JSON, life is good. Do $.post(...), not as much. It comes across as:
    name=test&address[0][city]=one&address[0][state]=a&address[1][city]=two&address[1][state]=b

    But Spring (the BeanWrapper) wants:
    name=test&address[0].city=one&address[0].state=a&address[1].city=two&address[1].state=b

    I wrote up a quick filter to inject a custom RequestWrapper around the request that does some magic to convert the parameter names. Seems to work, but is there a better way to do this? Or something in Spring that handles it?

  • #2
    bump.

    Anyone else run in to this? Or have thoughts on other ways to fix it?

    Comment

    Working...
    X