Created
September 24, 2014 12:54
-
-
Save whiter4bbit/c24d8f27112f5f253fa8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import org.apache.flume.sink.elasticsearch.ContentBuilderUtil; | |
import org.elasticsearch.common.xcontent.XContentBuilder; | |
import org.elasticsearch.common.xcontent.XContentFactory; | |
public class JsonPlay { | |
public static void main(String[] args) throws Exception { | |
XContentBuilder strangeBuilder = XContentFactory.jsonBuilder().startObject(); | |
ContentBuilderUtil.appendField(strangeBuilder, "data", "1\t{\"areYouSure\":\"thatItisvalidJson\"}".getBytes()); | |
System.out.println(strangeBuilder.bytes().toUtf8()); | |
XContentBuilder straightBuilder = XContentFactory.jsonBuilder().startObject(); | |
ContentBuilderUtil.appendField(straightBuilder, "data", "it is not json because don't contains brackets".getBytes()); | |
System.out.println(straightBuilder.bytes().toUtf8()); | |
} | |
} | |
/* | |
{"data":"org.elasticsearch.common.xcontent.XContentBuilder@560088f"} | |
{"data":"it is not json because don't contains brackets"} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment