use of org.codehaus.jackson.util.DefaultPrettyPrinter in project activityinfo by bedatadriven.
the class Jackson method createJsonFactory.
static JsonGenerator createJsonFactory(StringWriter writer) throws IOException {
JsonFactory jfactory = new JsonFactory();
JsonGenerator json = jfactory.createJsonGenerator(writer);
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
json.setPrettyPrinter(prettyPrinter);
return json;
}
use of org.codehaus.jackson.util.DefaultPrettyPrinter in project activityinfo by bedatadriven.
the class AdminLevelResource method getFeatures.
@GET
@Timed(name = "site.rest.admin.features")
@Path("/entities/features")
public Response getFeatures(@InjectParam EntityManager em) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(baos, Charsets.UTF_8);
List<AdminEntity> entities = em.createQuery("select e from AdminEntity e where e.deleted = false and e.level = :level").setParameter("level", level).getResultList();
JsonFactory jfactory = new JsonFactory();
JsonGenerator json = jfactory.createJsonGenerator(writer);
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
json.setPrettyPrinter(prettyPrinter);
json.writeStartObject();
json.writeStringField("type", "FeatureCollection");
json.writeFieldName("features");
json.writeStartArray();
GeometrySerializer geometrySerializer = new GeometrySerializer();
for (AdminEntity entity : entities) {
if (entity.getGeometry() != null) {
json.writeStartObject();
json.writeStringField("type", "Feature");
json.writeNumberField("id", entity.getId());
json.writeObjectFieldStart("properties");
json.writeStringField("name", entity.getName());
if (entity.getParentId() != null) {
json.writeNumberField("parentId", entity.getParentId());
}
json.writeEndObject();
json.writeFieldName("geometry");
geometrySerializer.writeGeometry(json, entity.getGeometry());
json.writeEndObject();
}
}
json.writeEndArray();
json.writeEndObject();
json.close();
return Response.ok().entity(baos.toByteArray()).type(MediaType.APPLICATION_JSON).build();
}
Aggregations