當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultPrettyPrinter類代碼示例

本文整理匯總了Java中com.fasterxml.jackson.core.util.DefaultPrettyPrinter的典型用法代碼示例。如果您正苦於以下問題:Java DefaultPrettyPrinter類的具體用法?Java DefaultPrettyPrinter怎麽用?Java DefaultPrettyPrinter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DefaultPrettyPrinter類屬於com.fasterxml.jackson.core.util包,在下文中一共展示了DefaultPrettyPrinter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: marshalJson

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
public static String marshalJson(CASServiceResponse serviceResponse) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    //Force newlines to be LF (default is system dependent)
    DefaultPrettyPrinter printer = new DefaultPrettyPrinter()
            .withObjectIndenter(new DefaultIndenter("  ", "\n"));

    //create wrapper node
    Map<String, Object> casModel = new HashMap<>();
    casModel.put("serviceResponse", serviceResponse);
    try {
        return mapper.writer(printer).writeValueAsString(casModel);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:Doccrazy,項目名稱:keycloak-protocol-cas,代碼行數:17,代碼來源:ServiceResponseMarshaller.java

示例2: testCustomSeparatorsWithPP

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
public void testCustomSeparatorsWithPP() throws Exception
{
    StringWriter sw = new StringWriter();
    JsonGenerator gen = new JsonFactory().createGenerator(ObjectWriteContext.empty(), sw);
    gen.setPrettyPrinter(new DefaultPrettyPrinter().withSeparators(Separators.createDefaultInstance()
            .withObjectFieldValueSeparator('=')
            .withObjectEntrySeparator(';')
            .withArrayValueSeparator('|')));

    _writeTestDocument(gen);
    gen.close();
    assertEquals("[ 3| \"abc\"| [ true ]| {" + DefaultIndenter.SYS_LF +
            "  \"f\" = null;" + DefaultIndenter.SYS_LF +
            "  \"f2\" = null" + DefaultIndenter.SYS_LF +
            "} ]", sw.toString());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:TestPrettyPrinter.java

示例3: testCustomSeparatorsWithPPWithoutSpaces

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
public void testCustomSeparatorsWithPPWithoutSpaces() throws Exception
{
    StringWriter sw = new StringWriter();
    JsonGenerator gen = new JsonFactory().createGenerator(ObjectWriteContext.empty(), sw);
    gen.setPrettyPrinter(new DefaultPrettyPrinter().withSeparators(Separators.createDefaultInstance()
            .withObjectFieldValueSeparator('=')
            .withObjectEntrySeparator(';')
            .withArrayValueSeparator('|'))
        .withoutSpacesInObjectEntries());

    _writeTestDocument(gen);
    gen.close();
    assertEquals("[ 3| \"abc\"| [ true ]| {" + DefaultIndenter.SYS_LF +
            "  \"f\"=null;" + DefaultIndenter.SYS_LF +
            "  \"f2\"=null" + DefaultIndenter.SYS_LF +
            "} ]", sw.toString());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:TestPrettyPrinter.java

示例4: objectMapper

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
public static ObjectMapper objectMapper() {
    return new ObjectMapper()
            // Property visibility
            .setDefaultPropertyInclusion(JsonInclude.Include.ALWAYS)
            .setDefaultVisibility(JsonAutoDetect.Value.construct(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.PROTECTED_AND_PUBLIC))
            .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .configure(SerializationFeature.WRITE_NULL_MAP_VALUES, true)

            // Property naming and order
            .setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE)

            // Customised de/serializers

            // Formats, locals, encoding, binary data
            .setDateFormat(new SimpleDateFormat("MM/dd/yyyy"))
            .setDefaultPrettyPrinter(new DefaultPrettyPrinter())
            .setLocale(Locale.CANADA);
}
 
開發者ID:readlearncode,項目名稱:JSON-framework-comparison,代碼行數:20,代碼來源:RuntimeSampler.java

示例5: exportTo

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
/**
 * Exports data to a {@link Writer}.
 *
 * @param writer the writer
 * @throws NitriteIOException if there is any error while writing the data.
 */
public void exportTo(Writer writer) {
    JsonGenerator generator;
    try {
        generator = jsonFactory.createGenerator(writer);
        generator.setPrettyPrinter(new DefaultPrettyPrinter());
    } catch (IOException ioe) {
        throw new NitriteIOException(EXPORT_WRITER_ERROR, ioe);
    }

    NitriteJsonExporter jsonExporter = new NitriteJsonExporter(db);
    jsonExporter.setGenerator(generator);
    jsonExporter.setOptions(options);
    try {
        jsonExporter.exportData();
    } catch (IOException | ClassNotFoundException e) {
        throw new NitriteIOException(EXPORT_WRITE_ERROR, e);
    }
}
 
開發者ID:dizitart,項目名稱:nitrite-database,代碼行數:25,代碼來源:Exporter.java

示例6: EclipseParser

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
/**
 * Creates a new EclipseParser
 *
 * @param sourceFile String of source file to read
 * @param outJ       JSON parsed out
 * @throws IOException when file can't be opened or errors in reading/writing
 */
public EclipseParser(String sourceFile, PrintStream outJ, boolean prettyprint) throws IOException {

    File file = new File(sourceFile);
    final BufferedReader reader = new BufferedReader(new FileReader(file));
    char[] source = IOUtils.toCharArray(reader);
    reader.close();
    this.parser = ASTParser.newParser(AST.JLS8);
    parser.setSource(source);
    parser.setKind(ASTParser.K_COMPILATION_UNIT);

    final JsonFactory jsonF = new JsonFactory();
    jG = jsonF.createGenerator(outJ);
    if (prettyprint) {
        jG.setPrettyPrinter(new DefaultPrettyPrinter());
        mapper.enable(SerializationFeature.INDENT_OUTPUT);
    }
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
    SimpleModule module = new SimpleModule();
    module.addSerializer(ASTNode.class, new NodeSerializer());
    mapper.registerModule(module);
}
 
開發者ID:bblfsh,項目名稱:java-driver,代碼行數:31,代碼來源:eclipseParser.java

示例7: createJsonWriter

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
@Nonnull
private static ObjectWriter createJsonWriter(final boolean prettyPrint) {
    final ObjectMapper mapper = new ObjectMapper();

    if (!prettyPrint) {
        return mapper.writer();
    }

    final DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter("    ", DefaultIndenter.SYS_LF);
    final DefaultPrettyPrinter printer = new DefaultPrettyPrinter("");
    printer.withoutSpacesInObjectEntries();
    printer.indentObjectsWith(indenter);
    printer.indentArraysWith(indenter);

    return mapper.writer(printer);
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:17,代碼來源:MapToJson.java

示例8: serializationEntityTypeTest

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
@Test
public void serializationEntityTypeTest() throws JsonProcessingException {
    ObjectWriter writer = Utils.objectMapper.writer(new DefaultPrettyPrinter());

    EntityType entityType = new EntityType();
    Map<String,AttributeType> attrs = new HashMap<>();
    AttributeType tempAttribute = new AttributeType("urn:phenomenum:temperature");
    attrs.put("temperature", tempAttribute);
    AttributeType humidityAttribute = new AttributeType("percentage");
    attrs.put("humidity", humidityAttribute);
    AttributeType pressureAttribute = new AttributeType("null");
    attrs.put("pressure", pressureAttribute);
    entityType.setAttrs(attrs);
    entityType.setCount(7);
    String json = writer.writeValueAsString(entityType);

    assertEquals(jsonString, json);
}
 
開發者ID:Orange-OpenSource,項目名稱:fiware-ngsi2-api,代碼行數:19,代碼來源:EntityTypeTest.java

示例9: serializationRegistrationTest

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
@Test
public void serializationRegistrationTest() throws JsonProcessingException, MalformedURLException {
    ObjectWriter writer = Utils.objectMapper.writer(new DefaultPrettyPrinter());

    Registration registration = new Registration("abcde", new URL("http://localhost:1234"));
    registration.setDuration("PT1M");
    SubjectEntity subjectEntity = new SubjectEntity();
    subjectEntity.setType(Optional.of("Room"));
    SubjectRegistration subjectRegistration = new SubjectRegistration(Collections.singletonList(subjectEntity), Collections.singletonList("humidity"));
    registration.setSubject(subjectRegistration);
    String json = writer.writeValueAsString(registration);
    String jsonString ="{\n" +
            "  \"id\" : \"abcde\",\n" +
            "  \"subject\" : {\n" +
            "    \"entities\" : [ {\n" +
            "      \"type\" : \"Room\"\n" +
            "    } ],\n" +
            "    \"attributes\" : [ \"humidity\" ]\n" +
            "  },\n" +
            "  \"callback\" : \"http://localhost:1234\",\n" +
            "  \"duration\" : \"PT1M\"\n" +
            "}";
    assertEquals(jsonString, json);
}
 
開發者ID:Orange-OpenSource,項目名稱:fiware-ngsi2-api,代碼行數:25,代碼來源:RegistrationTest.java

示例10: serializationEntityTest

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
@Test
public void serializationEntityTest() throws JsonProcessingException {
    ObjectWriter writer = Utils.objectMapper.writer(new DefaultPrettyPrinter());

    Entity entity = new Entity("Bcn-Welt", "Room");
    HashMap<String,Attribute> attributes = new HashMap<String, Attribute>();
    Attribute tempAttribute = new Attribute(21.7);
    attributes.put("temperature", tempAttribute);
    Attribute humidityAttribute = new Attribute(60);
    attributes.put("humidity", humidityAttribute);
    entity.setAttributes(attributes);
    String json = writer.writeValueAsString(entity);
    String jsonString = "{\n" +
            "  \"id\" : \"Bcn-Welt\",\n" +
            "  \"type\" : \"Room\",\n" +
            "  \"temperature\" : {\n" +
            "    \"value\" : 21.7,\n" +
            "    \"metadata\" : { }\n" +
            "  },\n" +
            "  \"humidity\" : {\n" +
            "    \"value\" : 60,\n" +
            "    \"metadata\" : { }\n" +
            "  }\n" +
            "}";
    assertEquals(jsonString, json);
}
 
開發者ID:Orange-OpenSource,項目名稱:fiware-ngsi2-api,代碼行數:27,代碼來源:EntityTest.java

示例11: serializationSubscriptionTest

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
@Test
public void serializationSubscriptionTest() throws JsonProcessingException, MalformedURLException {
    ObjectWriter writer = Utils.objectMapper.writer(new DefaultPrettyPrinter());

    SubjectEntity subjectEntity = new SubjectEntity();
    subjectEntity.setId(Optional.of("Bcn_Welt"));
    subjectEntity.setType(Optional.of("Room"));
    Condition condition = new Condition();
    condition.setAttributes(Collections.singletonList("temperature"));
    condition.setExpression("q", "temperature>40");
    SubjectSubscription subjectSubscription = new SubjectSubscription(Collections.singletonList(subjectEntity), condition);
    List<String> attributes = new ArrayList<>();
    attributes.add("temperature");
    attributes.add("humidity");
    Notification notification = new Notification(attributes, new URL("http://localhost:1234"));
    notification.setThrottling(Optional.of(new Long(5)));
    notification.setTimesSent(12);
    notification.setLastNotification(Instant.parse("2015-10-05T16:00:00.10Z"));
    notification.setHeader("X-MyHeader", "foo");
    notification.setQuery("authToken", "bar");
    notification.setAttrsFormat(Optional.of(Notification.Format.keyValues));
    String json = writer.writeValueAsString(new Subscription("abcdefg", subjectSubscription, notification, Instant.parse("2016-04-05T14:00:00.20Z"), Subscription.Status.active));

    assertEquals(jsonString, json);
}
 
開發者ID:Orange-OpenSource,項目名稱:fiware-ngsi2-api,代碼行數:26,代碼來源:SubscriptionTest.java

示例12: toString

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
/**
 @return The JSON pretty-printed representation of this configuration.
 */
@Override
public final String toString() {
	final ObjectMapper mapper = new ObjectMapper()
		.configure(SerializationFeature.INDENT_OUTPUT, true);
	final DefaultPrettyPrinter.Indenter indenter = new DefaultIndenter(
		"\t", DefaultIndenter.SYS_LF
	);
	final DefaultPrettyPrinter printer = new DefaultPrettyPrinter();
	printer.withObjectIndenter(indenter);
	printer.withArrayIndenter(indenter);
	try {
		return mapper.writer(printer).writeValueAsString(this);
	} catch(final JsonProcessingException e) {
		throw new AssertionError(e);
	}
}
 
開發者ID:emc-mongoose,項目名稱:mongoose-base,代碼行數:20,代碼來源:Config.java

示例13: getQueryResult

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
public Response getQueryResult(final Query query) {
	StreamingOutput stream = new StreamingOutput() {
		@Override
		public void write( OutputStream os ) throws IOException, WebApplicationException {
			JsonGenerator jg = objectMapper.getFactory().createGenerator(os, JsonEncoding.UTF8);
			jg.setPrettyPrinter(new DefaultPrettyPrinter());
			jg.writeStartObject();
			if (query != null && query.toCypher().length() > 0) {
				writeQueryDetails(jg, query);
				System.out.println(query.toCypher());
				executeQuery(jg, query);
			} else {
				jg.writeStringField("error", "No query supplied.");
			}
			jg.writeEndObject();
			jg.flush();
			jg.close();
		}
	};

	return Response.ok().entity( stream ).type( MediaType.APPLICATION_JSON ).build();
}
 
開發者ID:Taalmonsters,項目名稱:WhiteLab2.0-Neo4J-Plugin,代碼行數:23,代碼來源:CypherExecutor.java

示例14: serializationSimpleQueryContext

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
@Test
public void serializationSimpleQueryContext() throws IOException {
    QueryContext queryContext = createQueryContextTemperature();
    ObjectMapper mapper = new ObjectMapper();
    ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
    String json = writer.writeValueAsString(queryContext);

    List<EntityId> entityIdList = JsonPath.read(json, "$.entities[*]");
    assertEquals(1, entityIdList.size());
    assertEquals("S*", JsonPath.read(json, "$.entities[0].id"));
    assertEquals("TempSensor", JsonPath.read(json, "$.entities[0].type"));
    assertEquals(true, JsonPath.read(json, "$.entities[0].isPattern"));
    List<String> attributeList = JsonPath.read(json, "$.attributes[*]");
    assertEquals(1, attributeList.size());
    assertEquals("temp", JsonPath.read(json, "$.attributes[0]"));
}
 
開發者ID:Orange-OpenSource,項目名稱:fiware-ngsi-api,代碼行數:17,代碼來源:QueryContextModelTest.java

示例15: serializationSimpleRegisterContext

import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; //導入依賴的package包/類
@Test
public void serializationSimpleRegisterContext() throws URISyntaxException, JsonProcessingException {
    RegisterContext registerContext = createRegisterContextTemperature();
    ObjectMapper mapper = new ObjectMapper();
    ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
    String json = writer.writeValueAsString(registerContext);

    List<ContextRegistration> contextRegistrationList = JsonPath.read(json, "$.contextRegistrations[*]");
    assertEquals(1, contextRegistrationList.size());
    List<EntityId> entityIdList = JsonPath.read(json, "$.contextRegistrations[0].entities[*]");
    assertEquals(1, entityIdList.size());
    assertEquals("Room*", JsonPath.read(json, "$.contextRegistrations[0].entities[0].id"));
    assertEquals("Room", JsonPath.read(json, "$.contextRegistrations[0].entities[0].type"));
    assertEquals(true, JsonPath.read(json, "$.contextRegistrations[0].entities[0].isPattern"));
    List<ContextRegistrationAttribute> attributes = JsonPath.read(json, "$.contextRegistrations[0].attributes[*]");
    assertEquals(1, attributes.size());
    assertEquals("temperature", JsonPath.read(json, "$.contextRegistrations[0].attributes[0].name"));
    assertEquals("float", JsonPath.read(json, "$.contextRegistrations[0].attributes[0].type"));
    assertEquals(false, JsonPath.read(json, "$.contextRegistrations[0].attributes[0].isDomain"));
    assertEquals("http://localhost:1028/accumulate", JsonPath.read(json, "$.contextRegistrations[0].providingApplication"));
    assertEquals("PT10S", JsonPath.read(json, "$.duration"));

}
 
開發者ID:Orange-OpenSource,項目名稱:fiware-ngsi-api,代碼行數:24,代碼來源:RegisterContextModelTest.java


注:本文中的com.fasterxml.jackson.core.util.DefaultPrettyPrinter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。