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;
}
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();
}
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();
}
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;
}
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();
}
}
Aggregations