当前位置: 首页>>代码示例>>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;未经允许,请勿转载。