Search in sources :

Example 96 with JsonFactory

use of com.fasterxml.jackson.core.JsonFactory in project jackrabbit-oak by apache.

the class PatchRevisionHandler method handle.

@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
    RemoteSession session = (RemoteSession) request.getAttribute("session");
    if (session == null) {
        sendInternalServerError(response, "session not found");
        return;
    }
    RemoteRevision base = readRevision(request, session);
    if (base == null) {
        sendGone(response, "revision not found");
        return;
    }
    RemoteOperation operation;
    try {
        operation = parseOperations(session, new ObjectMapper().readTree(request.getInputStream()));
    } catch (Exception e) {
        operation = null;
    }
    if (operation == null) {
        sendBadRequest(response, "unable to parse the list of operations");
        return;
    }
    RemoteRevision revision;
    try {
        revision = session.commit(base, operation);
    } catch (RemoteCommitException e) {
        logger.warn("unable to perform the commit", e);
        sendBadRequest(response, "commit failed");
        return;
    }
    response.setStatus(HttpServletResponse.SC_CREATED);
    response.setContentType("application/json");
    ServletOutputStream stream = response.getOutputStream();
    JsonGenerator generator = new JsonFactory().createJsonGenerator(stream, JsonEncoding.UTF8);
    renderResponse(generator, revision);
    generator.flush();
    stream.close();
}
Also used : RemoteOperation(org.apache.jackrabbit.oak.remote.RemoteOperation) ServletOutputStream(javax.servlet.ServletOutputStream) RemoteCommitException(org.apache.jackrabbit.oak.remote.RemoteCommitException) RemoteSession(org.apache.jackrabbit.oak.remote.RemoteSession) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RemoteRevision(org.apache.jackrabbit.oak.remote.RemoteRevision) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RemoteCommitException(org.apache.jackrabbit.oak.remote.RemoteCommitException) IOException(java.io.IOException)

Example 97 with JsonFactory

use of com.fasterxml.jackson.core.JsonFactory in project sling by apache.

the class JacksonExporter method export.

@Override
public <T> T export(@Nonnull Object model, @Nonnull Class<T> clazz, @Nonnull Map<String, String> options) throws ExportException {
    ObjectMapper mapper = new ObjectMapper();
    for (Map.Entry<String, String> optionEntry : options.entrySet()) {
        String key = optionEntry.getKey();
        if (key.startsWith(SERIALIZATION_FEATURE_PREFIX)) {
            String enumName = key.substring(SERIALIZATION_FEATURE_PREFIX_LENGTH);
            try {
                SerializationFeature feature = SerializationFeature.valueOf(enumName);
                mapper.configure(feature, Boolean.valueOf(optionEntry.getValue()));
            } catch (IllegalArgumentException e) {
                log.warn("Bad SerializationFeature option");
            }
        } else if (key.startsWith(MAPPER_FEATURE_PREFIX)) {
            String enumName = key.substring(MAPPER_FEATURE_PREFIX_LENGTH);
            try {
                MapperFeature feature = MapperFeature.valueOf(enumName);
                mapper.configure(feature, Boolean.valueOf(optionEntry.getValue()));
            } catch (IllegalArgumentException e) {
                log.warn("Bad SerializationFeature option");
            }
        }
    }
    for (ModuleProvider moduleProvider : moduleProviders) {
        mapper.registerModule(moduleProvider.getModule());
    }
    if (clazz.equals(Map.class)) {
        return (T) mapper.convertValue(model, Map.class);
    } else if (clazz.equals(String.class)) {
        final JsonFactory f = new JsonFactory();
        f.setCharacterEscapes(new EscapeCloseScriptBlocks());
        StringWriter writer = new StringWriter();
        JsonGenerator jgen;
        final boolean printTidy;
        if (options.containsKey("tidy")) {
            printTidy = Boolean.valueOf(options.get("tidy"));
        } else {
            printTidy = false;
        }
        try {
            jgen = f.createGenerator(writer);
            if (printTidy) {
                mapper.writerWithDefaultPrettyPrinter().writeValue(jgen, model);
            } else {
                mapper.writeValue(jgen, model);
            }
        } catch (final IOException e) {
            throw new ExportException(e);
        }
        return (T) writer.toString();
    } else {
        return null;
    }
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) SerializableString(com.fasterxml.jackson.core.SerializableString) IOException(java.io.IOException) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) ExportException(org.apache.sling.models.factory.ExportException) ModuleProvider(org.apache.sling.models.jacksonexporter.ModuleProvider) StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 98 with JsonFactory

use of com.fasterxml.jackson.core.JsonFactory in project pyramid by cheng-li.

the class App2 method report.

static void report(Config config, String dataName, Logger logger) throws Exception {
    logger.info("generating reports for data set " + dataName);
    String output = config.getString("output.folder");
    String modelName = "model_app3";
    File analysisFolder = new File(new File(output, "reports_app3"), dataName + "_reports");
    analysisFolder.mkdirs();
    FileUtils.cleanDirectory(analysisFolder);
    IMLGradientBoosting boosting = IMLGradientBoosting.deserialize(new File(output, modelName));
    String predictTarget = config.getString("predict.target");
    PluginPredictor<IMLGradientBoosting> pluginPredictorTmp = null;
    switch(predictTarget) {
        case "subsetAccuracy":
            pluginPredictorTmp = new SubsetAccPredictor(boosting);
            break;
        case "hammingLoss":
            pluginPredictorTmp = new HammingPredictor(boosting);
            break;
        case "instanceFMeasure":
            pluginPredictorTmp = new InstanceF1Predictor(boosting);
            break;
        case "macroFMeasure":
            TunedMarginalClassifier tunedMarginalClassifier = (TunedMarginalClassifier) Serialization.deserialize(new File(output, "predictor_macro_f"));
            pluginPredictorTmp = new MacroF1Predictor(boosting, tunedMarginalClassifier);
            break;
        default:
            throw new IllegalArgumentException("unknown prediction target measure " + predictTarget);
    }
    // just to make Lambda expressions happy
    final PluginPredictor<IMLGradientBoosting> pluginPredictor = pluginPredictorTmp;
    MultiLabelClfDataSet dataSet = loadData(config, dataName);
    MLMeasures mlMeasures = new MLMeasures(pluginPredictor, dataSet);
    mlMeasures.getMacroAverage().setLabelTranslator(boosting.getLabelTranslator());
    logger.info("performance on dataset " + dataName);
    logger.info(mlMeasures.toString());
    boolean simpleCSV = true;
    if (simpleCSV) {
        logger.info("start generating simple CSV report");
        double probThreshold = config.getDouble("report.classProbThreshold");
        File csv = new File(analysisFolder, "report.csv");
        List<String> strs = IntStream.range(0, dataSet.getNumDataPoints()).parallel().mapToObj(i -> IMLGBInspector.simplePredictionAnalysis(boosting, pluginPredictor, dataSet, i, probThreshold)).collect(Collectors.toList());
        try (BufferedWriter bw = new BufferedWriter(new FileWriter(csv))) {
            for (int i = 0; i < dataSet.getNumDataPoints(); i++) {
                String str = strs.get(i);
                bw.write(str);
            }
        }
        logger.info("finish generating simple CSV report");
    }
    boolean rulesToJson = config.getBoolean("report.showPredictionDetail");
    if (rulesToJson) {
        logger.info("start writing rules to json");
        int ruleLimit = config.getInt("report.rule.limit");
        int numDocsPerFile = config.getInt("report.numDocsPerFile");
        int numFiles = (int) Math.ceil((double) dataSet.getNumDataPoints() / numDocsPerFile);
        double probThreshold = config.getDouble("report.classProbThreshold");
        int labelSetLimit = config.getInt("report.labelSetLimit");
        IntStream.range(0, numFiles).forEach(i -> {
            int start = i * numDocsPerFile;
            int end = start + numDocsPerFile;
            List<MultiLabelPredictionAnalysis> partition = IntStream.range(start, Math.min(end, dataSet.getNumDataPoints())).parallel().mapToObj(a -> IMLGBInspector.analyzePrediction(boosting, pluginPredictor, dataSet, a, ruleLimit, labelSetLimit, probThreshold)).collect(Collectors.toList());
            ObjectMapper mapper = new ObjectMapper();
            String file = "report_" + (i + 1) + ".json";
            try {
                mapper.writeValue(new File(analysisFolder, file), partition);
            } catch (IOException e) {
                e.printStackTrace();
            }
            logger.info("progress = " + Progress.percentage(i + 1, numFiles));
        });
        logger.info("finish writing rules to json");
    }
    boolean dataInfoToJson = true;
    if (dataInfoToJson) {
        logger.info("start writing data info to json");
        Set<String> modelLabels = IntStream.range(0, boosting.getNumClasses()).mapToObj(i -> boosting.getLabelTranslator().toExtLabel(i)).collect(Collectors.toSet());
        Set<String> dataSetLabels = DataSetUtil.gatherLabels(dataSet).stream().map(i -> dataSet.getLabelTranslator().toExtLabel(i)).collect(Collectors.toSet());
        JsonGenerator jsonGenerator = new JsonFactory().createGenerator(new File(analysisFolder, "data_info.json"), JsonEncoding.UTF8);
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField("dataSet", dataName);
        jsonGenerator.writeNumberField("numClassesInModel", boosting.getNumClasses());
        jsonGenerator.writeNumberField("numClassesInDataSet", dataSetLabels.size());
        jsonGenerator.writeNumberField("numClassesInModelDataSetCombined", dataSet.getNumClasses());
        Set<String> modelNotDataLabels = SetUtil.complement(modelLabels, dataSetLabels);
        Set<String> dataNotModelLabels = SetUtil.complement(dataSetLabels, modelLabels);
        jsonGenerator.writeNumberField("numClassesInDataSetButNotModel", dataNotModelLabels.size());
        jsonGenerator.writeNumberField("numClassesInModelButNotDataSet", modelNotDataLabels.size());
        jsonGenerator.writeArrayFieldStart("classesInDataSetButNotModel");
        for (String label : dataNotModelLabels) {
            jsonGenerator.writeObject(label);
        }
        jsonGenerator.writeEndArray();
        jsonGenerator.writeArrayFieldStart("classesInModelButNotDataSet");
        for (String label : modelNotDataLabels) {
            jsonGenerator.writeObject(label);
        }
        jsonGenerator.writeEndArray();
        jsonGenerator.writeNumberField("labelCardinality", dataSet.labelCardinality());
        jsonGenerator.writeEndObject();
        jsonGenerator.close();
        logger.info("finish writing data info to json");
    }
    boolean modelConfigToJson = true;
    if (modelConfigToJson) {
        logger.info("start writing model config to json");
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.writeValue(new File(analysisFolder, "model_config.json"), config);
        logger.info("finish writing model config to json");
    }
    boolean dataConfigToJson = true;
    if (dataConfigToJson) {
        logger.info("start writing data config to json");
        File dataConfigFile = Paths.get(config.getString("input.folder"), "data_sets", dataName, "data_config.json").toFile();
        if (dataConfigFile.exists()) {
            FileUtils.copyFileToDirectory(dataConfigFile, analysisFolder);
        }
        logger.info("finish writing data config to json");
    }
    boolean performanceToJson = true;
    if (performanceToJson) {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.writeValue(new File(analysisFolder, "performance.json"), mlMeasures);
    }
    boolean individualPerformance = true;
    if (individualPerformance) {
        logger.info("start writing individual label performance to json");
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.writeValue(new File(analysisFolder, "individual_performance.json"), mlMeasures.getMacroAverage());
        logger.info("finish writing individual label performance to json");
    }
    logger.info("reports generated");
}
Also used : IntStream(java.util.stream.IntStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) SimpleFormatter(java.util.logging.SimpleFormatter) PluginPredictor(edu.neu.ccs.pyramid.multilabel_classification.PluginPredictor) edu.neu.ccs.pyramid.multilabel_classification.imlgb(edu.neu.ccs.pyramid.multilabel_classification.imlgb) ArrayList(java.util.ArrayList) Terminator(edu.neu.ccs.pyramid.optimization.Terminator) FileHandler(java.util.logging.FileHandler) FeatureDistribution(edu.neu.ccs.pyramid.feature_selection.FeatureDistribution) JsonEncoding(com.fasterxml.jackson.core.JsonEncoding) Config(edu.neu.ccs.pyramid.configuration.Config) MultiLabelPredictionAnalysis(edu.neu.ccs.pyramid.multilabel_classification.MultiLabelPredictionAnalysis) EarlyStopper(edu.neu.ccs.pyramid.optimization.EarlyStopper) BufferedWriter(java.io.BufferedWriter) edu.neu.ccs.pyramid.eval(edu.neu.ccs.pyramid.eval) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TunedMarginalClassifier(edu.neu.ccs.pyramid.multilabel_classification.thresholding.TunedMarginalClassifier) FileWriter(java.io.FileWriter) Set(java.util.Set) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) StopWatch(org.apache.commons.lang3.time.StopWatch) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) File(java.io.File) Progress(edu.neu.ccs.pyramid.util.Progress) List(java.util.List) JsonFactory(com.fasterxml.jackson.core.JsonFactory) Feature(edu.neu.ccs.pyramid.feature.Feature) MacroFMeasureTuner(edu.neu.ccs.pyramid.multilabel_classification.thresholding.MacroFMeasureTuner) Serialization(edu.neu.ccs.pyramid.util.Serialization) Paths(java.nio.file.Paths) edu.neu.ccs.pyramid.dataset(edu.neu.ccs.pyramid.dataset) Vector(org.apache.mahout.math.Vector) TopFeatures(edu.neu.ccs.pyramid.feature.TopFeatures) SetUtil(edu.neu.ccs.pyramid.util.SetUtil) MultiLabelPredictionAnalysis(edu.neu.ccs.pyramid.multilabel_classification.MultiLabelPredictionAnalysis) FileWriter(java.io.FileWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) BufferedWriter(java.io.BufferedWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) TunedMarginalClassifier(edu.neu.ccs.pyramid.multilabel_classification.thresholding.TunedMarginalClassifier) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) File(java.io.File)

Example 99 with JsonFactory

use of com.fasterxml.jackson.core.JsonFactory in project pyramid by cheng-li.

the class App6 method report.

static void report(Config config, MultiLabelClfDataSet dataSet, String dataName) throws Exception {
    System.out.println("generating reports for data set " + dataName);
    String output = config.getString("output.folder");
    String modelName = "model_crf";
    File analysisFolder = new File(new File(output, "reports_crf"), dataName + "_reports");
    analysisFolder.mkdirs();
    FileUtils.cleanDirectory(analysisFolder);
    CMLCRF crf = (CMLCRF) Serialization.deserialize(new File(output, modelName));
    PluginPredictor<CMLCRF> predictorTmp = null;
    String predictTarget = config.getString("predict.target");
    switch(predictTarget) {
        case "subsetAccuracy":
            predictorTmp = new SubsetAccPredictor(crf);
            break;
        case "instanceFMeasure":
            predictorTmp = new InstanceF1Predictor(crf);
            break;
        default:
            throw new IllegalArgumentException("predict.target must be subsetAccuracy or instanceFMeasure");
    }
    // just to make Lambda expressions happy
    final PluginPredictor<CMLCRF> predictor = predictorTmp;
    MLMeasures mlMeasures = new MLMeasures(predictor, dataSet);
    mlMeasures.getMacroAverage().setLabelTranslator(crf.getLabelTranslator());
    System.out.println("performance on dataset " + dataName);
    System.out.println(mlMeasures);
    boolean simpleCSV = true;
    if (simpleCSV) {
        //            System.out.println("start generating simple CSV report");
        double probThreshold = config.getDouble("report.classProbThreshold");
        File csv = new File(analysisFolder, "report.csv");
        List<String> strs = IntStream.range(0, dataSet.getNumDataPoints()).parallel().mapToObj(i -> CRFInspector.simplePredictionAnalysis(crf, predictor, dataSet, i, probThreshold)).collect(Collectors.toList());
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < dataSet.getNumDataPoints(); i++) {
            String str = strs.get(i);
            sb.append(str);
        }
        FileUtils.writeStringToFile(csv, sb.toString(), false);
    //            System.out.println("finish generating simple CSV report");
    }
    boolean dataInfoToJson = true;
    if (dataInfoToJson) {
        //            System.out.println("start writing data info to json");
        Set<String> modelLabels = IntStream.range(0, crf.getNumClasses()).mapToObj(i -> crf.getLabelTranslator().toExtLabel(i)).collect(Collectors.toSet());
        Set<String> dataSetLabels = DataSetUtil.gatherLabels(dataSet).stream().map(i -> dataSet.getLabelTranslator().toExtLabel(i)).collect(Collectors.toSet());
        JsonGenerator jsonGenerator = new JsonFactory().createGenerator(new File(analysisFolder, "data_info.json"), JsonEncoding.UTF8);
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField("dataSet", dataName);
        jsonGenerator.writeNumberField("numClassesInModel", crf.getNumClasses());
        jsonGenerator.writeNumberField("numClassesInDataSet", dataSetLabels.size());
        jsonGenerator.writeNumberField("numClassesInModelDataSetCombined", dataSet.getNumClasses());
        Set<String> modelNotDataLabels = SetUtil.complement(modelLabels, dataSetLabels);
        Set<String> dataNotModelLabels = SetUtil.complement(dataSetLabels, modelLabels);
        jsonGenerator.writeNumberField("numClassesInDataSetButNotModel", dataNotModelLabels.size());
        jsonGenerator.writeNumberField("numClassesInModelButNotDataSet", modelNotDataLabels.size());
        jsonGenerator.writeArrayFieldStart("classesInDataSetButNotModel");
        for (String label : dataNotModelLabels) {
            jsonGenerator.writeObject(label);
        }
        jsonGenerator.writeEndArray();
        jsonGenerator.writeArrayFieldStart("classesInModelButNotDataSet");
        for (String label : modelNotDataLabels) {
            jsonGenerator.writeObject(label);
        }
        jsonGenerator.writeEndArray();
        jsonGenerator.writeNumberField("labelCardinality", dataSet.labelCardinality());
        jsonGenerator.writeEndObject();
        jsonGenerator.close();
    //            System.out.println("finish writing data info to json");
    }
    boolean modelConfigToJson = true;
    if (modelConfigToJson) {
        //            System.out.println("start writing model config to json");
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.writeValue(new File(analysisFolder, "model_config.json"), config);
    //            System.out.println("finish writing model config to json");
    }
    boolean performanceToJson = true;
    if (performanceToJson) {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.writeValue(new File(analysisFolder, "performance.json"), mlMeasures);
    }
    boolean individualPerformance = true;
    if (individualPerformance) {
        //            System.out.println("start writing individual label performance to json");
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.writeValue(new File(analysisFolder, "individual_performance.json"), mlMeasures.getMacroAverage());
    //            System.out.println("finish writing individual label performance to json");
    }
    System.out.println("reports generated");
}
Also used : edu.neu.ccs.pyramid.multilabel_classification.crf(edu.neu.ccs.pyramid.multilabel_classification.crf) IntStream(java.util.stream.IntStream) MacroF1Predictor(edu.neu.ccs.pyramid.multilabel_classification.imlgb.MacroF1Predictor) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) HammingPredictor(edu.neu.ccs.pyramid.multilabel_classification.imlgb.HammingPredictor) PluginPredictor(edu.neu.ccs.pyramid.multilabel_classification.PluginPredictor) FeatureDistribution(edu.neu.ccs.pyramid.feature_selection.FeatureDistribution) JsonEncoding(com.fasterxml.jackson.core.JsonEncoding) LBFGS(edu.neu.ccs.pyramid.optimization.LBFGS) Accuracy(edu.neu.ccs.pyramid.eval.Accuracy) Overlap(edu.neu.ccs.pyramid.eval.Overlap) Config(edu.neu.ccs.pyramid.configuration.Config) MultiLabelPredictionAnalysis(edu.neu.ccs.pyramid.multilabel_classification.MultiLabelPredictionAnalysis) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TunedMarginalClassifier(edu.neu.ccs.pyramid.multilabel_classification.thresholding.TunedMarginalClassifier) FMeasure(edu.neu.ccs.pyramid.eval.FMeasure) Set(java.util.Set) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) IMLGradientBoosting(edu.neu.ccs.pyramid.multilabel_classification.imlgb.IMLGradientBoosting) TimeUnit(java.util.concurrent.TimeUnit) Progress(edu.neu.ccs.pyramid.util.Progress) IMLGBInspector(edu.neu.ccs.pyramid.multilabel_classification.imlgb.IMLGBInspector) List(java.util.List) JsonFactory(com.fasterxml.jackson.core.JsonFactory) MLMeasures(edu.neu.ccs.pyramid.eval.MLMeasures) Serialization(edu.neu.ccs.pyramid.util.Serialization) PrintUtil(edu.neu.ccs.pyramid.util.PrintUtil) Paths(java.nio.file.Paths) Handlers.output(edu.stanford.nlp.util.logging.RedwoodConfiguration.Handlers.output) edu.neu.ccs.pyramid.dataset(edu.neu.ccs.pyramid.dataset) TopFeatures(edu.neu.ccs.pyramid.feature.TopFeatures) SetUtil(edu.neu.ccs.pyramid.util.SetUtil) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) File(java.io.File) MLMeasures(edu.neu.ccs.pyramid.eval.MLMeasures) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 100 with JsonFactory

use of com.fasterxml.jackson.core.JsonFactory in project CFLint by cflint.

the class JSONOutput method output.

public void output(final BugList bugList, final Writer writer, final boolean showStats) throws IOException {
    final BugCounts counts = new BugCounts();
    // final StringBuilder sb = new StringBuilder();
    final JsonFactory jsonF = new JsonFactory();
    final JsonGenerator jg = jsonF.createGenerator(writer);
    if (prettyPrint) {
        jg.useDefaultPrettyPrinter();
    }
    jg.writeStartArray();
    List<String> keys = new ArrayList<String>(bugList.getBugList().keySet());
    Collections.sort(keys);
    for (final String key : keys) {
        List<BugInfo> currentList = bugList.getBugList().get(key);
        final Iterator<BugInfo> iterator = currentList.iterator();
        BugInfo bugInfo = iterator.hasNext() ? iterator.next() : null;
        BugInfo prevbugInfo;
        while (bugInfo != null) {
            final String severity = currentList.get(0).getSeverity();
            final String code = currentList.get(0).getMessageCode();
            counts.add(code, severity);
            jg.writeStartObject();
            jg.writeStringField("severity", notNull(severity));
            jg.writeStringField("id", code);
            jg.writeStringField("message", code);
            jg.writeStringField("category", "CFLINT");
            jg.writeStringField("abbrev", abbrev(code));
            jg.writeFieldName("locations");
            jg.writeStartArray();
            do {
                jg.writeStartObject();
                jg.writeStringField("file", notNull(bugInfo.getFilename()));
                jg.writeStringField("fileName", filename(bugInfo.getFilename()));
                jg.writeStringField("function", filename(bugInfo.getFunction()));
                jg.writeStringField("column", Integer.valueOf(bugInfo.getColumn()).toString());
                jg.writeStringField("line", Integer.valueOf(bugInfo.getLine()).toString());
                jg.writeStringField("message", notNull(bugInfo.getMessage()));
                jg.writeStringField("variable", notNull(bugInfo.getVariable()));
                jg.writeStringField("expression", notNull(bugInfo.getExpression()));
                jg.writeEndObject();
                prevbugInfo = bugInfo;
                bugInfo = iterator.hasNext() ? iterator.next() : null;
            } while (isGrouped(prevbugInfo, bugInfo));
            jg.writeEndArray();
            jg.writeEndObject();
        }
    }
    if (showStats) {
        for (final String code : counts.bugTypes()) {
            jg.writeStartObject();
            jg.writeStringField("code", code);
            jg.writeStringField("count", Integer.toString(counts.getCode(code)));
            jg.writeEndObject();
        }
        for (final String severity : BugCounts.levels) {
            if (counts.getSeverity(severity) > 0) {
                jg.writeStartObject();
                jg.writeStringField("severity", severity);
                jg.writeStringField("count", Integer.toString(counts.getSeverity(severity)));
                jg.writeEndObject();
            }
        }
    }
    jg.writeEndArray();
    jg.close();
    writer.close();
}
Also used : JsonFactory(com.fasterxml.jackson.core.JsonFactory) ArrayList(java.util.ArrayList) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)101 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)39 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 Test (org.junit.Test)31 StringWriter (java.io.StringWriter)29 JsonParser (com.fasterxml.jackson.core.JsonParser)24 ExtensibleJSONWriter (com.instagram.common.json.annotation.processor.support.ExtensibleJSONWriter)15 IOException (java.io.IOException)14 Map (java.util.Map)14 HashMap (java.util.HashMap)11 SimpleParseUUT (com.instagram.common.json.annotation.processor.uut.SimpleParseUUT)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 FileInputStream (java.io.FileInputStream)6 ServletOutputStream (javax.servlet.ServletOutputStream)6 Reader (java.io.Reader)5 RemoteSession (org.apache.jackrabbit.oak.remote.RemoteSession)5 File (java.io.File)4 JSONWriter (org.json.JSONWriter)4 BaseJsonHttpResponseHandler (com.loopj.android.http.BaseJsonHttpResponseHandler)3