Permalink
Browse files

GStrings were not bein parsed properly in JSON sentences so I needed

to cast them as Strings first
  • Loading branch information...
mpermar committed Feb 5, 2011
1 parent ce4c336 commit 89c2819d15b1a480ba7fa2a0b6a22b44f9d56a0b
Showing with 28 additions and 0 deletions.
  1. +28 −0 src/groovy/com/tropo/grails/TropoBuilder.groovy
@@ -1,6 +1,8 @@
package com.tropo.grails
import grails.util.GrailsWebUtil;
+import groovy.lang.GString;
+
import javax.servlet.http.HttpServletResponse;
import java.net.URL;
@@ -86,6 +88,7 @@ class TropoBuilder extends BuilderSupport {
}
} else {
+ map = cleanGStrings(map)
def newNode = new JSONObject()
newNode.putAll more
validate(name,newNode)
@@ -131,6 +134,7 @@ class TropoBuilder extends BuilderSupport {
private JSONObject buildElement(String name, Map map) {
//println "I would now insert node ${name} in stack element ${stack.peek()}"
+ map = cleanGStrings(map)
def node = stack.peek()
def element = new JSONObject()
@@ -167,6 +171,7 @@ class TropoBuilder extends BuilderSupport {
private JSONObject buildArray(String name, Map map) {
+ map = cleanGStrings(map)
//println "I would now insert node ${name} in stack element ${stack.peek()}"
def node = stack.peek()
def created
@@ -272,6 +277,7 @@ class TropoBuilder extends BuilderSupport {
protected Object createNode(Object name, Object value) {
//println "Invoking createNode(object arg0, object arg1) with args ${name} and ${value}. Current: ${getCurrent()}"
+ value = cleanGStrings(value)
if (name == "say") {
if (!(value instanceof String) && !(value instanceof Map) && !(value instanceof List)) {
@@ -370,4 +376,26 @@ class TropoBuilder extends BuilderSupport {
root.put("tropo",[])
stack.push root.tropo
}
+
+ private Object cleanGStrings(Object value) {
+
+ if (value instanceof GString) {
+ return value as String
+ } else if (value instanceof Map) {
+ value.each {
+ if (it.value instanceof GString) {
+ it.value = it.value as String
+ }
+ }
+ } else if (value instanceof List) {
+ value.each {
+ if (it instanceof String) {
+ it = it as String
+ }
+ }
+ }
+ return value
+ }
+
+
}

0 comments on commit 89c2819

Please sign in to comment.