Search in sources :

Example 91 with JsonGenerator

use of 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 92 with JsonGenerator

use of com.fasterxml.jackson.core.JsonGenerator in project Payara by payara.

the class ProgressStatusJsonProvider method writeTo.

@Override
public void writeTo(ProgressStatusBase proxy, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    JsonGenerator out = factory.createJsonGenerator(entityStream, JsonEncoding.UTF8);
    out.writeStartObject();
    writeJson("progress-status", proxy, -1, out);
    out.writeEndObject();
    out.flush();
}
Also used : JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 93 with JsonGenerator

use of com.fasterxml.jackson.core.JsonGenerator in project dhis2-core by dhis2.

the class OrganisationUnitController method getGeoJson.

@RequestMapping(value = "", method = RequestMethod.GET, produces = { "application/json+geo", "application/json+geojson" })
public void getGeoJson(@RequestParam(value = "level", required = false) List<Integer> rpLevels, @RequestParam(value = "parent", required = false) List<String> rpParents, @RequestParam(value = "properties", required = false, defaultValue = "true") boolean rpProperties, User currentUser, HttpServletResponse response) throws IOException {
    rpLevels = rpLevels != null ? rpLevels : new ArrayList<>();
    rpParents = rpParents != null ? rpParents : new ArrayList<>();
    List<OrganisationUnit> parents = manager.getByUid(OrganisationUnit.class, rpParents);
    if (rpLevels.isEmpty()) {
        rpLevels.add(1);
    }
    if (parents.isEmpty()) {
        parents.addAll(organisationUnitService.getRootOrganisationUnits());
    }
    List<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsAtLevels(rpLevels, parents);
    response.setContentType("application/json");
    JsonFactory jsonFactory = new JsonFactory();
    JsonGenerator generator = jsonFactory.createGenerator(response.getOutputStream());
    generator.writeStartObject();
    generator.writeStringField("type", "FeatureCollection");
    generator.writeArrayFieldStart("features");
    for (OrganisationUnit organisationUnit : organisationUnits) {
        writeFeature(generator, organisationUnit, rpProperties, currentUser);
    }
    generator.writeEndArray();
    generator.writeEndObject();
    generator.close();
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ArrayList(java.util.ArrayList) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 94 with JsonGenerator

use of com.fasterxml.jackson.core.JsonGenerator in project graphhopper by graphhopper.

the class GraphHopperServletModule method createObjectMapper.

@Provides
@Singleton
ObjectMapper createObjectMapper() {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setDateFormat(new ISO8601DateFormat());
    objectMapper.registerModule(new JtsModule());
    SimpleModule pathDetailModule = new SimpleModule();
    pathDetailModule.addSerializer(PathDetail.class, new PathDetailSerializer());
    pathDetailModule.addDeserializer(PathDetail.class, new PathDetailDeserializer());
    objectMapper.registerModule(pathDetailModule);
    // Because VirtualEdgeIteratorState has getters which throw Exceptions.
    // http://stackoverflow.com/questions/35359430/how-to-make-jackson-ignore-properties-if-the-getters-throw-exceptions
    objectMapper.registerModule(new SimpleModule().setSerializerModifier(new BeanSerializerModifier() {

        @Override
        public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
            return beanProperties.stream().map(bpw -> new BeanPropertyWriter(bpw) {

                @Override
                public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception {
                    try {
                        super.serializeAsField(bean, gen, prov);
                    } catch (Exception e) {
                    // Ignoring expected exception, see above.
                    }
                }
            }).collect(Collectors.toList());
        }
    }));
    return objectMapper;
}
Also used : JsonParser(com.fasterxml.jackson.core.JsonParser) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) BeanPropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter) CmdArgs(com.graphhopper.util.CmdArgs) IOException(java.io.IOException) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) ServletModule(com.google.inject.servlet.ServletModule) Collectors(java.util.stream.Collectors) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) List(java.util.List) Provides(com.google.inject.Provides) JtsModule(com.bedatadriven.jackson.datatype.jts.JtsModule) ISO8601DateFormat(com.fasterxml.jackson.databind.util.ISO8601DateFormat) Map(java.util.Map) BeanSerializerModifier(com.fasterxml.jackson.databind.ser.BeanSerializerModifier) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) com.fasterxml.jackson.databind(com.fasterxml.jackson.databind) PathDetail(com.graphhopper.util.details.PathDetail) ISO8601DateFormat(com.fasterxml.jackson.databind.util.ISO8601DateFormat) IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JtsModule(com.bedatadriven.jackson.datatype.jts.JtsModule) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) List(java.util.List) BeanPropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) BeanSerializerModifier(com.fasterxml.jackson.databind.ser.BeanSerializerModifier) Singleton(javax.inject.Singleton) Provides(com.google.inject.Provides)

Example 95 with JsonGenerator

use of com.fasterxml.jackson.core.JsonGenerator in project jmxtrans by jmxtrans.

the class SensuWriter2 method write.

@Override
public void write(@Nonnull Writer writer, @Nonnull Server server, @Nonnull Query query, @Nonnull Iterable<Result> results) throws IOException {
    try (JsonGenerator g = jsonFactory.createGenerator(writer);
        StringWriter temporaryWriter = new StringWriter()) {
        g.useDefaultPrettyPrinter();
        g.writeStartObject();
        g.writeStringField("name", "jmxtrans");
        g.writeStringField("type", "metric");
        g.writeStringField("handler", "graphite");
        graphiteWriter.write(temporaryWriter, server, query, results);
        g.writeStringField("output", temporaryWriter.toString());
        g.writeEndObject();
        g.flush();
    }
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Aggregations

JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)187 StringWriter (java.io.StringWriter)81 IOException (java.io.IOException)52 JsonFactory (com.fasterxml.jackson.core.JsonFactory)44 ByteArrayOutputStream (java.io.ByteArrayOutputStream)25 Map (java.util.Map)17 OutputStream (java.io.OutputStream)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 JsonParser (com.fasterxml.jackson.core.JsonParser)11 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 Test (org.junit.Test)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 File (java.io.File)7 OutputStreamWriter (java.io.OutputStreamWriter)6 ServletOutputStream (javax.servlet.ServletOutputStream)6 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)6 List (java.util.List)5 AccessExecutionVertex (org.apache.flink.runtime.executiongraph.AccessExecutionVertex)5 JsonEncoding (com.fasterxml.jackson.core.JsonEncoding)4