Hi there, I'm using Sequel 3.38.0 and ActiveSupport 3.2.6.
I'm trying to use the JSON Serializer plugin to generate JSON for some nested model structures. The project that I'm working on also makes use of some ActiveSupport features. Unfortunately, this appears to create a conflict when ActiveSupport overrides the to_json methods on Hash and Array. I've found a workaround in monkeypatching the monkeypatched Hash and Array classes, but it's pretty ugly. Is there a better way? Here's a sample gist that shows the conflict: <script src="https://gist.github.com/3371268.js"> </script> Running this script will produce the following: Good JSON [{"name":"Bob","id":1,"albums":[{"label":"Summer","tracks":[{"id":1,"length":10,"json_class":"Track"},{"id":2,"length":20,"json_class":"Track"}],"id":1,"json_class":"Album"},{"label":"Winter","tracks":[{"id":3,"length":30,"json_class":"Track"},{"id":4,"length":40,"json_class":"Track"}],"id":2,"json_class":"Album"}],"json_class":"Artist"}] Bad JSON [{"json":"{\"name\":\"Bob\",\"id\":1,\"albums\":[{\"json\":\"{\\\"label\\\":\\\"Summer\\\",\\\"tracks\\\":[{\\\"id\\\":1,\\\"length\\\":10},{\\\"id\\\":2,\\\"length\\\":20}],\\\"id\\\":1,\\\"json_class\\\":\\\"Album\\\"}\"},{\"json\":\"{\\\"label\\\":\\\"Winter\\\",\\\"tracks\\\":[{\\\"id\\\":3,\\\"length\\\":30},{\\\"id\\\":4,\\\"length\\\":40}],\\\"id\\\":2,\\\"json_class\\\":\\\"Album\\\"}\"}],\"json_class\":\"Artist\"}"}] Good JSON, ugly workaround [{"name":"Bob","id":1,"albums":[{"label":"Summer","tracks":[{"id":1,"length":10,"json_class":"Track"},{"id":2,"length":20,"json_class":"Track"}],"id":1,"json_class":"Album"},{"label":"Winter","tracks":[{"id":3,"length":30,"json_class":"Track"},{"id":4,"length":40,"json_class":"Track"}],"id":2,"json_class":"Album"}],"json_class":"Artist"}] Is there a better workaround or some configuration step I'm missing? Thanks, Alex -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/Ftm0WlggNyYJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
