Search in sources :

Example 51 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project geode by apache.

the class PdxToJSON method getJSONByteArray.

public byte[] getJSONByteArray() {
    JsonFactory jf = new JsonFactory();
    HeapDataOutputStream hdos = new HeapDataOutputStream(org.apache.geode.internal.Version.CURRENT);
    try {
        JsonGenerator jg = jf.createJsonGenerator(hdos, JsonEncoding.UTF8);
        enableDisableJSONGeneratorFeature(jg);
        getJSONString(jg, m_pdxInstance);
        jg.close();
        return hdos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage());
    } finally {
        hdos.close();
    }
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException)

Example 52 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project winery by eclipse.

the class VisualAppearanceResource method getConnectionTypeForJsPlumbData.

@GET
@ApiOperation(value = "@return JSON object to be used at jsPlumb.registerConnectionType('NAME', <data>)")
@Produces(MediaType.APPLICATION_JSON)
public Response getConnectionTypeForJsPlumbData() {
    JsonFactory jsonFactory = new JsonFactory();
    StringWriter sw = new StringWriter();
    try {
        JsonGenerator jg = jsonFactory.createGenerator(sw);
        jg.writeStartObject();
        jg.writeFieldName("connector");
        jg.writeString("Flowchart");
        jg.writeFieldName("paintStyle");
        jg.writeStartObject();
        jg.writeFieldName("lineWidth");
        jg.writeNumber(this.getLineWidth());
        jg.writeFieldName("strokeStyle");
        jg.writeObject(this.getColor());
        String dash = this.getDash();
        if (!StringUtils.isEmpty(dash)) {
            String dashStyle = null;
            switch(dash) {
                case "dotted":
                    dashStyle = "1 5";
                    break;
                case "dotted2":
                    dashStyle = "3 4";
                    break;
                case "plain":
                    // otherwise, "1 0" can be used
                    break;
            }
            if (dashStyle != null) {
                jg.writeStringField("dashstyle", dashStyle);
            }
        }
        jg.writeEndObject();
        jg.writeFieldName("hoverPaintStyle");
        jg.writeStartObject();
        jg.writeFieldName("strokeStyle");
        jg.writeObject(this.getHoverColor());
        jg.writeEndObject();
        jg.writeStringField("dash", getDash());
        jg.writeStringField("sourceArrowHead", this.getSourceArrowHead());
        jg.writeStringField("targetArrowHead", this.getTargetArrowHead());
        jg.writeStringField("color", this.getColor());
        jg.writeStringField("hoverColor", this.getHoverColor());
        // BEGIN: Overlays
        jg.writeFieldName("overlays");
        jg.writeStartArray();
        // source arrow head
        String head = this.getSourceArrowHead();
        if (!head.equals("none")) {
            jg.writeStartArray();
            jg.writeString(head);
            jg.writeStartObject();
            jg.writeFieldName("location");
            jg.writeNumber(0);
            // arrow should point towards the node and not away from it
            jg.writeFieldName("direction");
            jg.writeNumber(-1);
            jg.writeFieldName("width");
            jg.writeNumber(20);
            jg.writeFieldName("length");
            jg.writeNumber(12);
            jg.writeEndObject();
            jg.writeEndArray();
        }
        // target arrow head
        head = this.getTargetArrowHead();
        if (!head.equals("none")) {
            jg.writeStartArray();
            jg.writeString(head);
            jg.writeStartObject();
            jg.writeFieldName("location");
            jg.writeNumber(1);
            jg.writeFieldName("width");
            jg.writeNumber(20);
            jg.writeFieldName("length");
            jg.writeNumber(12);
            jg.writeEndObject();
            jg.writeEndArray();
        }
        // Type in brackets on the arrow
        jg.writeStartArray();
        jg.writeString("Label");
        jg.writeStartObject();
        jg.writeStringField("id", "label");
        jg.writeStringField("label", "(" + this.res.getName() + ")");
        jg.writeStringField("cssClass", "relationshipTypeLabel");
        jg.writeFieldName("location");
        jg.writeNumber(0.5);
        jg.writeEndObject();
        jg.writeEndArray();
        jg.writeEndArray();
        // END: Overlays
        jg.writeEndObject();
        jg.close();
    } catch (Exception e) {
        VisualAppearanceResource.LOGGER.error(e.getMessage(), e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e).build();
    }
    String res = sw.toString();
    return Response.ok(res).build();
}
Also used : StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 53 with JsonGenerator

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

the class IdentityReportExecutor method generateData.

@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
    File temp = null;
    FileOutputStream outputStream = null;
    try {
        // prepare temp file for json stream
        temp = getAttachmentManager().createTempFile();
        outputStream = new FileOutputStream(temp);
        // write into json stream
        JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
        try {
            // json will be array of identities
            jGenerator.writeStartArray();
            // form instance has useful methods to transform form values
            IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, getFormDefinition(), report.getFilter());
            // initialize filter by given form - transform to multi value map
            // => form attribute defined above will be automaticaly mapped to identity filter
            IdmIdentityFilter filter = new IdmIdentityFilter(formInstance.toMultiValueMap());
            // report extends long running task - show progress by count and counter lrt attributes
            counter = 0L;
            // find a first page of identities
            Pageable pageable = new PageRequest(0, 100, new Sort(Direction.ASC, IdmIdentity_.username.getName()));
            do {
                Page<IdmIdentityDto> identities = identityService.find(filter, pageable, IdmBasePermission.READ);
                if (count == null) {
                    // report extends long running task - show progress by count and counter lrt attributes
                    count = identities.getTotalElements();
                }
                boolean canContinue = true;
                for (Iterator<IdmIdentityDto> i = identities.iterator(); i.hasNext() && canContinue; ) {
                    // write single identity into json
                    getMapper().writeValue(jGenerator, i.next());
                    // 
                    // supports cancel report generating (report extends long running task)
                    ++counter;
                    canContinue = updateState();
                }
                // iterate while next page of identities is available
                pageable = identities.hasNext() && canContinue ? identities.nextPageable() : null;
            } while (pageable != null);
            // 
            // close array of identities
            jGenerator.writeEndArray();
        } finally {
            // close json stream
            jGenerator.close();
        }
        // save create temp file with array of identities in json as attachment
        return createAttachment(report, new FileInputStream(temp));
    } catch (IOException ex) {
        throw new ReportGenerateException(report.getName(), ex);
    } finally {
        // just for sure - jGenerator should close stream itself
        IOUtils.closeQuietly(outputStream);
        FileUtils.deleteQuietly(temp);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) FileInputStream(java.io.FileInputStream) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Sort(org.springframework.data.domain.Sort) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) File(java.io.File)

Example 54 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project project-build-plugin by axonivy.

the class YamlOptionsFactory method toYaml.

public static String toYaml(DeployToEngineMojo config) throws IOException {
    StringWriter writer = new StringWriter();
    JsonGenerator gen = yamlFactory.createGenerator(writer);
    // root
    gen.writeStartObject();
    writeTestUsers(config, gen);
    writeConfig(config, gen);
    writeTarget(config, gen);
    gen.writeEndObject();
    gen.close();
    String yaml = writer.toString();
    if (yaml.equals("{}\n")) {
        return null;
    }
    return yaml;
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 55 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project oap by oaplatform.

the class DictionaryParser method serialize.

private static void serialize(DictionaryRoot dictionary, Path path, boolean format) {
    try (JsonGenerator jsonGenerator = format ? Binder.json.getJsonGenerator(path).useDefaultPrettyPrinter() : Binder.json.getJsonGenerator(path)) {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField(NAME, dictionary.name);
        writeProperties(jsonGenerator, dictionary);
        writeValues(jsonGenerator, dictionary.getValues());
        jsonGenerator.writeEndObject();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Aggregations

JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)704 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 KriptonByteArrayOutputStream (com.abubusoft.kripton.common.KriptonByteArrayOutputStream)257 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)257 JacksonWrapperSerializer (com.abubusoft.kripton.persistence.JacksonWrapperSerializer)257 IOException (java.io.IOException)169 StringWriter (java.io.StringWriter)144 JsonFactory (com.fasterxml.jackson.core.JsonFactory)101 ByteArrayOutputStream (java.io.ByteArrayOutputStream)66 Map (java.util.Map)57 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)54 HashMap (java.util.HashMap)40 Test (org.junit.Test)30 File (java.io.File)27 ArrayList (java.util.ArrayList)25 OutputStream (java.io.OutputStream)24 Writer (java.io.Writer)22 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)21 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)20 FileOutputStream (java.io.FileOutputStream)19