SchemaBuilder { public String toJson() { try { return JsonSerializer.toString(this); } catch (IOException e) { throw new IndexException(e, "Unformateable JSON schema: {}", e.getMessage()); } } @JsonCreator  SchemaBuilder(@JsonProperty("default_analyzer") String defaultAnalyzerName,
                  @JsonProperty("analyzers") Map<String, AnalyzerBuilder> analyzerBuilders,
                  @JsonProperty("fields") Map<String, MapperBuilder<?, ?>> mapperBuilders); SchemaBuilder defaultAnalyzer(String name); SchemaBuilder analyzer(String name, AnalyzerBuilder analyzer); SchemaBuilder mapper(String field, MapperBuilder<?, ?> mapper); Schema build(); String toJson(); static SchemaBuilder fromJson(String json);  }
@Test public void testToJson() throws IOException { String json = schema().defaultAnalyzer("custom") .analyzer("custom", classpathAnalyzer("org.apache.lucene.analysis.en.EnglishAnalyzer")) .analyzer("snowball", snowballAnalyzer("English", "the,at")) .mapper("big_int", bigIntegerMapper().digits(10)) .mapper("big_dec", bigDecimalMapper()) .mapper("bitemporal", bitemporalMapper("vtFrom", "vtTo", "ttFrom", "ttTo")) .mapper("blob", blobMapper()) .mapper("bool", booleanMapper()) .mapper("date", dateMapper()) .mapper("date_range", dateRangeMapper("from", "to")) .mapper("double", doubleMapper()) .mapper("float", floatMapper()) .mapper("geo", geoPointMapper("lat", "lon")) .mapper("inet", inetMapper()) .mapper("int", integerMapper().boost(0.3f)) .mapper("long", longMapper()) .mapper("string", stringMapper()) .mapper("text", textMapper()) .mapper("uuid", uuidMapper()) .toJson(); String expectedJson = "{default_analyzer:\"custom\"," + "analyzers:{" + "custom:{type:\"classpath\",class:\"org.apache.lucene.analysis.en.EnglishAnalyzer\"}," + "snowball:{type:\"snowball\",language:\"English\",stopwords:\"the,at\"}}," + "fields:" + "{big_int:{type:\"bigint\",digits:10}," + "big_dec:{type:\"bigdec\"}," + "bitemporal:{type:\"bitemporal\"," + "vt_from:\"vtFrom\",vt_to:\"vtTo\",tt_from:\"ttFrom\",tt_to:\"ttTo\"}," + "blob:{type:\"bytes\"}," + "bool:{type:\"boolean\"}," + "date:{type:\"date\"}," + "date_range:{type:\"date_range\",from:\"from\",to:\"to\"}," + "double:{type:\"double\"}," + "float:{type:\"float\"}," + "geo:{type:\"geo_point\",latitude:\"lat\",longitude:\"lon\"}," + "inet:{type:\"inet\"}," + "int:{type:\"integer\",boost:0.3}," + "long:{type:\"long\"}," + "string:{type:\"string\"}," + "text:{type:\"text\"}," + "uuid:{type:\"uuid\"}}}"; assertEquals("Failed schema JSON serialization", expectedJson, json); }