Search in sources :

Example 96 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project hippo by NHS-digital-website.

the class OdsUtils method main.

public static void main(String[] args) throws IOException {
    OdsUtils util = new OdsUtils();
    int offSet = 1;
    List<Organisation> finalList = new ArrayList();
    while (true) {
        String str = util.extracted(String.valueOf(offSet)).toString().trim();
        System.out.println("Value is " + str.length());
        List<Organisation> tempList = util.jsonFomart(str);
        System.out.println("Value is tempList " + tempList.size());
        if (tempList != null && tempList.size() > 0) {
            finalList.addAll(tempList);
            offSet += 1000;
            System.out.println("Value of offSet is " + offSet);
            System.out.println("Size of finalList is " + finalList.size());
        } else {
            break;
        }
    }
    ObjectMapper objectMapper = new ObjectMapper();
    // Set pretty printing of json
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    ObjectWriter writer = objectMapper.writer(new DefaultPrettyPrinter());
    writer.writeValue(new File("ODS_JSON.json"), finalList);
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) ArrayList(java.util.ArrayList) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 97 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project cxf by apache.

the class Java2SwaggerMojo method generateSwaggerPayLoad.

private void generateSwaggerPayLoad() throws MojoExecutionException {
    if (outputFile == null && project != null) {
        // Put the json in target/generated/json
        // put the yaml in target/generated/yaml
        final String name;
        if (outputFileName != null) {
            name = outputFileName;
        } else if (resourceClasses.size() == 1) {
            name = resourceClasses.iterator().next().getSimpleName();
        } else {
            name = "swagger";
        }
        outputFile = (project.getBuild().getDirectory() + "/generated/" + payload.toLowerCase() + "/" + name + "." + payload.toLowerCase()).replace("/", File.separator);
    }
    FileUtils.mkDir(new File(outputFile).getParentFile());
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {
        if ("json".equals(this.payload)) {
            ObjectWriter jsonWriter = mapper.writer(new DefaultPrettyPrinter());
            writer.write(jsonWriter.writeValueAsString(swagger));
        } else if ("yaml".equals(this.payload)) {
            writer.write(Yaml.pretty().writeValueAsString(swagger));
        }
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    // with the enclosing project
    if (attachSwagger && outputFile != null) {
        File jsonFile = new File(outputFile);
        if (jsonFile.exists()) {
            if (classifier != null) {
                projectHelper.attachArtifact(project, payload.toLowerCase(), classifier, jsonFile);
            } else {
                projectHelper.attachArtifact(project, payload.toLowerCase(), jsonFile);
            }
        }
    }
}
Also used : DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileWriter(java.io.FileWriter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 98 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project CzechIdMng by bcvsolutions.

the class DefaultRecaptchaRestTest method jsonify.

private String jsonify(RecaptchaRequest dto) throws IOException {
    ObjectMapper m = new ObjectMapper();
    StringWriter sw = new StringWriter();
    ObjectWriter writer = m.writerFor(RecaptchaRequest.class);
    writer.writeValue(sw, dto);
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 99 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project snow-owl by b2ihealthcare.

the class CsvMessageConverter method writeInternal.

@Override
protected void writeInternal(Collection<Object> items, HttpOutputMessage output) throws IOException, HttpMessageNotWritableException {
    if (!items.isEmpty()) {
        output.getHeaders().setContentType(MEDIA_TYPE);
        output.getHeaders().set(CONTENT_DISPOSITION, ATTACHMENT);
        try (OutputStream out = output.getBody()) {
            final CsvMapper mapper = new CsvMapper();
            mapper.readerFor(Collection.class);
            // XXX The mapper is auto closing the writer after the first write out for some reason
            mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
            final CsvSchema schema = mapper.schemaFor(items.iterator().next().getClass()).withHeader().withColumnSeparator('\t');
            final ObjectWriter writer = mapper.writer(schema);
            writer.writeValues(out).writeAll(items);
        }
    }
}
Also used : CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) OutputStream(java.io.OutputStream) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter)

Example 100 with ObjectWriter

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project CzechIdMng by bcvsolutions.

the class NotificationRestTest method jsonify.

String jsonify(IdmNotificationDto dto) throws IOException {
    ObjectMapper m = new ObjectMapper();
    StringWriter sw = new StringWriter();
    ObjectWriter writer = m.writerFor(IdmNotificationDto.class);
    writer.writeValue(sw, dto);
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)140 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)61 IOException (java.io.IOException)31 Test (org.junit.Test)30 File (java.io.File)17 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)15 ArrayList (java.util.ArrayList)12 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)11 JavaType (com.fasterxml.jackson.databind.JavaType)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)7 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 StringWriter (java.io.StringWriter)7 Map (java.util.Map)7 JCommander (com.beust.jcommander.JCommander)6 ParameterException (com.beust.jcommander.ParameterException)6 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)6 RateLimiter (com.google.common.util.concurrent.RateLimiter)6 FileInputStream (java.io.FileInputStream)6