nifi-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattyb149 <...@git.apache.org>
Subject [GitHub] nifi pull request #2063: NIFI-4269 Added the ability to serialize Mongo docu...
Date Tue, 22 Aug 2017 14:01:39 GMT
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2063#discussion_r134487688
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/GetMongo.java
---
    @@ -151,17 +172,34 @@ public ValidationResult validate(final String subject, final String
value, final
             return propertyDescriptors;
         }
     
    -    private ObjectMapper mapper = new ObjectMapper();
    +    private ObjectMapper mapper;
     
         //Turn a list of Mongo result documents into a String representation of a JSON array
    -    private String buildBatch(List<Document> documents) throws IOException {
    -        List<Map> docs = new ArrayList<>();
    -        for (Document document : documents) {
    -            String asJson = document.toJson();
    -            docs.add(mapper.readValue(asJson, Map.class));
    +    private String buildBatch(List<Document> documents, String jsonTypeSetting)
throws IOException {
    +        StringBuilder builder = new StringBuilder();
    +        for (int index = 0; index < documents.size(); index++) {
    +            Document document = documents.get(index);
    +            String asJson;
    +            if (jsonTypeSetting.equals(JSON_TYPE_NORMAL)) {
    +                asJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(document);
    +            } else {
    +                asJson = document.toJson(new JsonWriterSettings(true));
    +            }
    +            builder
    +                .append(asJson)
    +                .append( (documents.size() > 1 && index + 1 < documents.size())
? ", " : "" );
             }
     
    -        return mapper.writeValueAsString(docs);
    +        return "[" + builder.toString() + "]"; //mapper.writerWithDefaultPrettyPrinter().writeValueAsString(docs);
    --- End diff --
    
    This looks like a dead code comment, if it doesn't inform the line please remove :)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message