HtmlSerializer implements Serializer { @Override public InputStream serialize(InputStream rawContent, DataSetMetadata metadata, long limit) { try { PipedInputStream pipe = new PipedInputStream(); PipedOutputStream jsonOutput = new PipedOutputStream(pipe); Runnable r = () -> deserialize(rawContent, metadata, jsonOutput, limit); executor.execute(r); return pipe; } catch (IOException e) { throw new TDPException(CommonErrorCodes.UNABLE_TO_SERIALIZE_TO_JSON, e); } }  @Override InputStream serialize(InputStream rawContent, DataSetMetadata metadata, long limit);  }
@Test public void html_serializer() throws Exception { final SchemaParser.Request request; final Schema result; try (InputStream inputStream = this.getClass().getResourceAsStream("sales-force.xls")) { request = getRequest(inputStream, "#2"); request.getMetadata().setEncoding("UTF-16"); result = htmlSchemaGuesser.parse(request); } try (InputStream inputStream = this.getClass().getResourceAsStream("sales-force.xls")) { request.getMetadata().getRowMetadata().setColumns(result.getSheetContents().get(0).getColumnMetadatas()); InputStream jsonStream = htmlSerializer.serialize(inputStream, request.getMetadata(), -1); String json = IOUtils.toString(jsonStream, UTF_8); logger.debug("json: {}", json); ObjectMapper mapper = new ObjectMapper(); CollectionType collectionType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, TreeMap.class); List<Map<String, String>> values = mapper.readValue(json, collectionType); logger.debug("values: {}", values); Map<String, String> row0 = values.get(0); Assertions.assertThat(row0).contains(MapEntry.entry("0000", "000001"), MapEntry.entry("0001", "aaa"), MapEntry.entry("0002", "France"), MapEntry.entry("0003", "x@talend.com")); } }
@Test public void html_serializer_with_jira_export() throws Exception { final SchemaParser.Request request; final Schema result; try (InputStream inputStream = this.getClass().getResourceAsStream("jira_export.xls")) { request = getRequest(inputStream, "#2"); request.getMetadata().setEncoding("UTF-16"); result = htmlSchemaGuesser.parse(request); } try (InputStream inputStream = this.getClass().getResourceAsStream("jira_export.xls")) { final List<ColumnMetadata> columns = result.getSheetContents().get(0).getColumnMetadatas(); Assert.assertThat(columns.size(), is(98)); request.getMetadata().getRowMetadata().setColumns(columns); InputStream jsonStream = htmlSerializer.serialize(inputStream, request.getMetadata(), -1); String json = IOUtils.toString(jsonStream, UTF_8); ObjectMapper mapper = new ObjectMapper(); CollectionType collectionType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, TreeMap.class); List<Map<String, String>> values = mapper.readValue(json, collectionType); Map<String, String> row0 = values.get(0); for (String s : row0.keySet()) { row0.put(s, row0.get(s).trim()); } Assertions.assertThat(row0).contains(MapEntry.entry("0001", "TDP-1")); } }