Permalink
Browse files

Merge pull request #65 from infrastructor/feature/json-string-parsing…

…-support

add support to directly parse Strings with the 'json' helper function
  • Loading branch information...
tiurikov committed Nov 10, 2017
2 parents c79c4a9 + de23809 commit ae42cce1b9b281cf4c5805f0377f705cf0d15ca4
@@ -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 ae42cce

Please sign in to comment.