ivaynberg/select2 — pull request #2699 by sanguedemonstro (2014-09-25 16:54:22+00:00)
Title: Supporting json objects as value for multi-select

I have a multi-select loading ajax data, combined with an input instead of a select.
The value attribute contain a stringifyed json object array, like that:
{"id":46,"text":"Santa Catarina"},{"id":6,"text":"São Paulo"}

The problem is that getVal splits by default separator ',':

getVal expected result (2 records):
{"id":46,"text":"Santa Catarina"}
{"id":6,"text":"São Paulo"}

getVal current result (4 records):
{"id":46
"text":"Santa Catarina"}
{"id":6
"text":"São Paulo"}

As you can see at diff, I'm using a customized id and initSelection functions to deal with json objects.
And it's not possible (at least, it would be very, very painful and kinda ugly) to replace every json array with a custom separator between elements, on every JSON.Stringify (client), or Newtonsoft.Serialize (server).

So I'm proposing this adjust for multi-select getVal.

I'm using select2 for both: single and multi-select on our product, always with this 'json as value' approach.. all fine so far :)