@Test public void shouldConvertFeatureSetsAsJsonStringBytes() throws InvalidProtocolBufferException { int nrOfFeatureSet = 1; int nrOfFeatures = 1; List<FeatureSetProto.FeatureSet> featureSets = IntStream.range(1, nrOfFeatureSet + 1) .mapToObj(i -> newFeatureSet(nrOfFeatures)) .collect(Collectors.toList()); String expectedOutputString = "{\"entities\":[{\"name\":\"entity\",\"valueType\":2}]," + "\"features\":[{\"name\":\"feature1\",\"valueType\":6}]," + "\"source\":{" + "\"type\":1," + "\"kafkaSourceConfig\":{" + "\"bootstrapServers\":\"somebrokers:9092\"," + "\"topic\":\"sometopic\"}}}"; FeatureSetJsonByteConverter byteConverter = new FeatureSetJsonByteConverter(); assertEquals(expectedOutputString, new String(byteConverter.toByte(featureSets))); }
@Override public byte[] toByte(List<FeatureSetProto.FeatureSet> featureSets) throws InvalidProtocolBufferException { JsonFormat.Printer printer = JsonFormat.printer().omittingInsignificantWhitespace().printingEnumsAsInts(); List<String> featureSetsJson = new ArrayList<>(); for (FeatureSetProto.FeatureSet featureSet : featureSets) { featureSetsJson.add(printer.print(featureSet.getSpec())); } return String.join("\n", featureSetsJson).getBytes(); }
FeatureSetJsonByteConverter implements OptionByteConverter<List<FeatureSetProto.FeatureSet>> { @Override public byte[] toByte(List<FeatureSetProto.FeatureSet> featureSets) throws InvalidProtocolBufferException { JsonFormat.Printer printer = JsonFormat.printer().omittingInsignificantWhitespace().printingEnumsAsInts(); List<String> featureSetsJson = new ArrayList<>(); for (FeatureSetProto.FeatureSet featureSet : featureSets) { featureSetsJson.add(printer.print(featureSet.getSpec())); } return String.join("\n", featureSetsJson).getBytes(); } }
FeatureSetJsonByteConverter implements OptionByteConverter<List<FeatureSetProto.FeatureSet>> { @Override public byte[] toByte(List<FeatureSetProto.FeatureSet> featureSets) throws InvalidProtocolBufferException { JsonFormat.Printer printer = JsonFormat.printer().omittingInsignificantWhitespace().printingEnumsAsInts(); List<String> featureSetsJson = new ArrayList<>(); for (FeatureSetProto.FeatureSet featureSet : featureSets) { featureSetsJson.add(printer.print(featureSet.getSpec())); } return String.join("\n", featureSetsJson).getBytes(); }  }
FeatureSetJsonByteConverter implements OptionByteConverter<List<FeatureSetProto.FeatureSet>> { @Override public byte[] toByte(List<FeatureSetProto.FeatureSet> featureSets) throws InvalidProtocolBufferException { JsonFormat.Printer printer = JsonFormat.printer().omittingInsignificantWhitespace().printingEnumsAsInts(); List<String> featureSetsJson = new ArrayList<>(); for (FeatureSetProto.FeatureSet featureSet : featureSets) { featureSetsJson.add(printer.print(featureSet.getSpec())); } return String.join("\n", featureSetsJson).getBytes(); }  @Override byte[] toByte(List<FeatureSetProto.FeatureSet> featureSets); }
FeatureSetJsonByteConverter implements OptionByteConverter<List<FeatureSetProto.FeatureSet>> { @Override public byte[] toByte(List<FeatureSetProto.FeatureSet> featureSets) throws InvalidProtocolBufferException { JsonFormat.Printer printer = JsonFormat.printer().omittingInsignificantWhitespace().printingEnumsAsInts(); List<String> featureSetsJson = new ArrayList<>(); for (FeatureSetProto.FeatureSet featureSet : featureSets) { featureSetsJson.add(printer.print(featureSet.getSpec())); } return String.join("\n", featureSetsJson).getBytes(); }  @Override byte[] toByte(List<FeatureSetProto.FeatureSet> featureSets);  }