Created
May 29, 2012 07:17
-
-
Save sebastianbenz/2823082 to your computer and use it in GitHub Desktop.
Creating Json in Xtend.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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