Permalink
Browse files

add support to directly parse Strings with the 'json' helper function

  • Loading branch information...
tiurikov committed Nov 10, 2017
1 parent c79c4a9 commit de23809566487fdef743a9ff1907540cc44e63ee
@@ -7,5 +7,9 @@ class JsonUtils {
def static json(def content) {
new JsonSlurper().parse(content)
}
def static json(String content) {
new JsonSlurper().parseText(content)
}
}
@@ -0,0 +1,21 @@
package io.infrastructor.core.utils
import org.junit.Test
import static io.infrastructor.core.utils.JsonUtils.*
class JsonUtilsTest {
@Test
public void parseDataFromString() {
def result = json '{ "message": "simple" }'
assert result.message == "simple"
}
@Test
public void parseDataFromStream() {
def result = json (new ByteArrayInputStream('{ "message": "simple" }' as byte []))
assert result.message == "simple"
}
}

0 comments on commit de23809

Please sign in to comment.