List of usage examples for com.fasterxml.jackson.core.util DefaultPrettyPrinter DefaultPrettyPrinter
public DefaultPrettyPrinter()
From source file:com.ibm.ws.lars.rest.FrontPage.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType(MediaType.APPLICATION_JSON); resp.setCharacterEncoding(StandardCharsets.UTF_8.name()); PrintWriter printWriter = resp.getWriter(); List<AssetFilter> filters = new ArrayList<>(); filters.add(new AssetFilter("state", Arrays.asList(new Condition[] { new Condition(Operation.EQUALS, "published") }))); int assetCount = serviceLayer.countAllAssets(filters, null); JsonGenerator frontPageJsonGenerator = new JsonFactory().createGenerator(printWriter); frontPageJsonGenerator.setPrettyPrinter(new DefaultPrettyPrinter()); frontPageJsonGenerator.writeStartObject(); frontPageJsonGenerator.writeStringField("serverName", "LARS"); frontPageJsonGenerator.writeNumberField("assetCount", assetCount); frontPageJsonGenerator.writeEndObject(); frontPageJsonGenerator.flush();//from w w w .j av a 2s . c o m frontPageJsonGenerator.close(); }
From source file:com.vethrfolnir.services.DataMappingService.java
@Inject private void load() { if (assetManager == null) { throw new RuntimeException( "AssetManaget has not been set in your setup! Mapping service cannot be performed!"); }/*from w w w . j a va 2s . com*/ defaultTypeFactory = TypeFactory.defaultInstance(); jsonMapper.setVisibilityChecker(jsonMapper.getDeserializationConfig().getDefaultVisibilityChecker() .withCreatorVisibility(JsonAutoDetect.Visibility.NONE) .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE)); jsonMapper.configure(SerializationFeature.INDENT_OUTPUT, true).configure(Feature.ALLOW_COMMENTS, true); defaultPrettyPrinter = new DefaultPrettyPrinter(); defaultPrettyPrinter.indentArraysWith(new Lf2SpacesIndenter()); }
From source file:org.easyrec.taglib.ProfileRenderer.java
public ProfileRenderer() { super();//from www .j a va 2s .c o m this.mapper = new ObjectMapper(); this.writer = mapper.writer(new DefaultPrettyPrinter()); }
From source file:com.orange.ngsi.model.SubscribeContextModelTest.java
@Test public void serializationSimpleSubscribeContext() throws IOException { SubscribeContext subscribeContext = null; try {/*from ww w . ja v a2s . c om*/ subscribeContext = createSubscribeContextTemperature(); } catch (URISyntaxException e) { Assert.fail(e.getMessage()); } ObjectMapper mapper = new ObjectMapper(); ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter()); String json = writer.writeValueAsString(subscribeContext); List<EntityId> entityIdList = JsonPath.read(json, "$.entities[*]"); assertEquals(1, entityIdList.size()); assertEquals("Room1", JsonPath.read(json, "$.entities[0].id")); assertEquals("Room", JsonPath.read(json, "$.entities[0].type")); assertEquals(false, JsonPath.read(json, "$.entities[0].isPattern")); assertEquals("P1M", JsonPath.read(json, "$.duration")); List<String> attributes = JsonPath.read(json, "$.attributes[*]"); assertEquals(1, attributes.size()); assertEquals("temperature", JsonPath.read(json, "$.attributes[0]")); assertEquals("http://localhost:1028/accumulate", JsonPath.read(json, "$.reference")); List<NotifyCondition> notifyConditionList = JsonPath.read(json, "$.notifyConditions[*]"); assertEquals(1, notifyConditionList.size()); assertEquals(NotifyConditionEnum.ONTIMEINTERVAL.getLabel(), JsonPath.read(json, "$.notifyConditions[0].type")); List<String> condValues = JsonPath.read(json, "$.notifyConditions[0].condValues[*]"); assertEquals(1, condValues.size()); assertEquals("PT10S", JsonPath.read(json, "$.notifyConditions[0].condValues[0]")); }
From source file:org.emfjson.jackson.streaming.StreamWriter.java
private void prepare(JsonGenerator generator, Resource resource) { if (isPrepared) return;/* w ww. j av a 2 s. c o m*/ if (options.indentOutput) { DefaultPrettyPrinter printer = new DefaultPrettyPrinter(); generator.setPrettyPrinter(printer); } if (refWriter == null) { refWriter = new RefAsObjectWriter(); } if (!converters.containsKey(EcorePackage.Literals.EDATE)) { converters.put(EcorePackage.Literals.EDATE, new DefaultDateConverter()); } referenceWriter = new References(cache, resource, refWriter, options); values = new Values(converters); isPrepared = true; }
From source file:org.ratpackframework.jackson.JacksonModule.java
/** * Creates an object writer based on the bound {@link ObjectMapper} and the {@link #isPrettyPrint()} value. * * @param objectMapper The object mapper. * @return An object writer.// w ww.ja v a 2 s . co m */ @Provides @Singleton ObjectWriter objectWriter(ObjectMapper objectMapper) { return objectMapper.writer(isPrettyPrint() ? new DefaultPrettyPrinter() : new MinimalPrettyPrinter()); }
From source file:com.boundary.zoocreeper.Backup.java
public void backup(OutputStream os) throws InterruptedException, IOException, KeeperException { JsonGenerator jgen = null;/* w ww .ja v a 2s.co m*/ ZooKeeper zk = null; try { zk = options.createZooKeeper(LOGGER); jgen = JSON_FACTORY.createGenerator(os); if (options.prettyPrint) { jgen.setPrettyPrinter(new DefaultPrettyPrinter()); } jgen.writeStartObject(); if (zk.exists(options.rootPath, false) == null) { LOGGER.warn("Root path not found: {}", options.rootPath); } else { doBackup(zk, jgen, options.rootPath); } jgen.writeEndObject(); } finally { if (jgen != null) { jgen.close(); } if (zk != null) { zk.close(); } } }
From source file:org.forgerock.openig.migrate.Main.java
void execute(OutputStream stream) throws Exception { // Pre-parse the original files with JSON-Simple parser (which is more lenient than Jackson's one) File source = new File(sources.get(0)); JSONParser parser = new JSONParser(); JSONObject object = (JSONObject) parser.parse(new FileReader(source)); // Then serialize again the structure (should clean up the JSON) StringWriter writer = new StringWriter(); object.writeJSONString(writer);/*from w ww . j a v a 2s.co m*/ // Load migration actions to apply in order List<Action> actions = loadActions(); // Parse the cleaned-up content with Jackson this time JsonFactory factory = new JsonFactory(); ObjectMapper mapper = new ObjectMapper(); ObjectNode node = (ObjectNode) mapper.readTree(writer.toString()); // Apply migration actions for (Action action : actions) { node = action.migrate(node); } // Serialize the migrated content on the given stream (with pretty printer) DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter(); prettyPrinter.indentArraysWith(DefaultPrettyPrinter.Lf2SpacesIndenter.instance); mapper.writeTree(factory.createGenerator(stream).setPrettyPrinter(prettyPrinter), node); }
From source file:org.apache.arrow.vector.file.json.JsonFileWriter.java
public JsonFileWriter(File outputFile, JSONWriteConfig config) throws IOException { MappingJsonFactory jsonFactory = new MappingJsonFactory(); this.generator = jsonFactory.createGenerator(outputFile, JsonEncoding.UTF8); if (config.pretty) { DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter(); prettyPrinter.indentArraysWith(NopIndenter.instance); this.generator.setPrettyPrinter(prettyPrinter); }/*from ww w .jav a 2s . co m*/ }
From source file:com.effektif.workflow.impl.json.JsonStreamMapper.java
public <T> void write(T bean, Writer writer) { try {//ww w. j a v a 2s . c o m JsonGenerator jgen = new JsonFactory().createGenerator(writer); if (pretty) { jgen.setPrettyPrinter(new DefaultPrettyPrinter()); } JsonStreamWriter jsonStreamWriter = new JsonStreamWriter(mappings, jgen); jsonStreamWriter.writeObject(bean); jgen.flush(); } catch (IOException e) { throw new RuntimeException(e); } }