/* (non-Javadoc)
  * @see org.apache.solr.schema.FieldType#toExternal(org.apache.lucene.document.Fieldable)
  */
 @Override
 public String toExternal(Fieldable f) {
   if (f.isBinary()) {
     try {
       return CompressedField.decompressString(
           f.getBinaryValue(), f.getBinaryOffset(), f.getBinaryLength());
     } catch (DataFormatException e) {
       return super.toExternal(f);
     }
   } else {
     return super.toExternal(f);
   }
 }
  @Test
  public void testIncludeExclude() throws Exception {
    String mapping =
        XContentFactory.jsonBuilder()
            .startObject()
            .startObject("type")
            .startObject("_source")
            .field("includes", new String[] {"path1*"})
            .endObject()
            .endObject()
            .endObject()
            .string();

    DocumentMapper documentMapper = MapperTests.newParser().parse(mapping);

    ParsedDocument doc =
        documentMapper.parse(
            "type",
            "1",
            XContentFactory.jsonBuilder()
                .startObject()
                .startObject("path1")
                .field("field1", "value1")
                .endObject()
                .startObject("path2")
                .field("field2", "value2")
                .endObject()
                .endObject()
                .copiedBytes());

    Fieldable sourceField = doc.rootDoc().getFieldable("_source");
    Map<String, Object> sourceAsMap =
        XContentFactory.xContent(XContentType.JSON)
            .createParser(
                sourceField.getBinaryValue(),
                sourceField.getBinaryOffset(),
                sourceField.getBinaryLength())
            .mapAndClose();
    assertThat(sourceAsMap.containsKey("path1"), equalTo(true));
    assertThat(sourceAsMap.containsKey("path2"), equalTo(false));
  }