Skip to content

Instantly share code, notes, and snippets.

@whiter4bbit
Created September 24, 2014 12:54
Show Gist options
  • Save whiter4bbit/c24d8f27112f5f253fa8 to your computer and use it in GitHub Desktop.
Save whiter4bbit/c24d8f27112f5f253fa8 to your computer and use it in GitHub Desktop.
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