Skip to content

Instantly share code, notes, and snippets.

@sebastianbenz
Created May 29, 2012 07:17
Show Gist options
  • Save sebastianbenz/2823082 to your computer and use it in GitHub Desktop.
Save sebastianbenz/2823082 to your computer and use it in GitHub Desktop.
Creating Json in Xtend.
package json
import org.eclipse.xtext.xbase.lib.Pair
import java.util.List
import com.google.common.collect.Maps
class Json {
def static void main(String[] args) {
val json = map(
"aa" -> 111,
"bb" -> list(4,5,6),
"cc" -> map(
"dd" -> "777"
)
)
println(json)
}
def static <K, V> map(Pair<?, ?>... entries){
val result = Maps::<Object, Object>newHashMap
entries.forEach[
result.put(key, value)
]
return result
}
def static <T> List<T> list(T... entries){
return newArrayList(entries)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment