当前位置: 首页>>代码示例>>Java>>正文


Java DefaultIndenter类代码示例

本文整理汇总了Java中com.fasterxml.jackson.core.util.DefaultIndenter的典型用法代码示例。如果您正苦于以下问题:Java DefaultIndenter类的具体用法?Java DefaultIndenter怎么用?Java DefaultIndenter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DefaultIndenter类属于com.fasterxml.jackson.core.util包,在下文中一共展示了DefaultIndenter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: marshalJson

import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的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.DefaultIndenter; //导入依赖的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.DefaultIndenter; //导入依赖的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: createJsonWriter

import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的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

示例5: toString

import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的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

示例6: afterPropertiesSet

import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
@Override
public void afterPropertiesSet() {
    super.setModules(this.modules);

    super.afterPropertiesSet();

    ObjectMapper objMapper = this.getObject();
    DefaultIndenter indenter = new DefaultIndenter(StringUtils.repeat(StringUtils.SPACE, this.indentSize), StringUtils.LF);

    SdcctPrettyPrinter prettyPrinter = new SdcctPrettyPrinter(indenter.getIndent());
    prettyPrinter.indentArraysWith(indenter);
    prettyPrinter.indentObjectsWith(indenter);

    objMapper.setDefaultPrettyPrinter(prettyPrinter);

    objMapper.setPropertyInclusion(this.propInclusion);
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:18,代码来源:SdcctObjectMapperFactoryBean.java

示例7: prettyPrint

import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
@SuppressWarnings("unused")
private static void prettyPrint(String json) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode node = mapper.readTree(json);

    CustomPrettyPrinter prettyPrinter = new CustomPrettyPrinter();
    prettyPrinter.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE);
    StringBuilder sb = new StringBuilder();
    JsonGenerator jg = mapper.getFactory().createGenerator(CharStreams.asWriter(sb))
            .setPrettyPrinter(prettyPrinter);
    jg.writeTree(node);
    jg.close();

    System.out.println(sb.toString().replace("\"", "\\\"").replace(DefaultIndenter.SYS_LF,
            "\"" + DefaultIndenter.SYS_LF + " + \""));
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:17,代码来源:MutableProfileTest.java

示例8: prettyMapper

import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
private static ObjectMapper prettyMapper() {
	ObjectMapper mapper = new ObjectMapper();
	mapper.setBase64Variant(Base64Variants.MODIFIED_FOR_URL);
	mapper.configure(SerializationFeature.INDENT_OUTPUT, true);

	mapper.registerModule(tuuidModule());

	if (!Env.dev()) {
		mapper.registerModule(new AfterburnerModule());
	}

	DefaultPrettyPrinter pp = new DefaultPrettyPrinter();
	pp = pp.withObjectIndenter(new DefaultIndenter("  ", "\n"));

	mapper.setDefaultPrettyPrinter(pp);

	return mapper;
}
 
开发者ID:rapidoid,项目名称:rapidoid,代码行数:19,代码来源:JSON.java

示例9: getObjectWriter

import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
/**
 * Static factory that creates {@link com.fasterxml.jackson.databind.ObjectWriter}s.
 *
 * @return utility that will allow client to serialize wrapper contents as json
 */
public static ObjectWriter getObjectWriter(boolean filterMeta) {
	DefaultIndenter withLinefeed = new DefaultIndenter("  ", "\n");
	DefaultPrettyPrinter printer = new DefaultPrettyPrinter();
	printer.indentObjectsWith(withLinefeed);
	ObjectMapper om = new ObjectMapper();

	if (filterMeta) {
		outfitMetadataFilter(om);
	}

	return om.writer().with(printer);
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:18,代码来源:JsonWrapper.java

示例10: JacksonPrettyPrinter

import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
public JacksonPrettyPrinter(int indent) {
    super();
    StringBuilder indentSpaces = new StringBuilder();
    while (indentSpaces.length() < indent)
        indentSpaces.append(" ");
    super._objectIndenter = new DefaultIndenter(indentSpaces.toString(), DefaultIndenter.SYS_LF);
    super._arrayIndenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE;
}
 
开发者ID:limberest,项目名称:limberest,代码行数:9,代码来源:JacksonPrettyPrinter.java

示例11: NpmJsonPrettyPrinter

import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
public NpmJsonPrettyPrinter() {
    this._objectFieldValueSeparatorWithSpaces = ": ";

    Indenter indenter = new DefaultIndenter("  ", System.lineSeparator());
    this.indentObjectsWith(indenter);
    this.indentArraysWith(indenter);
}
 
开发者ID:fabric8-updatebot,项目名称:updatebot,代码行数:8,代码来源:NpmJsonPrettyPrinter.java

示例12: afterPropertiesSet

import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
@Override
public void afterPropertiesSet() {
    super.afterPropertiesSet();

    DefaultIndenter indenter = new DefaultIndenter(StringUtils.repeat(StringUtils.SPACE, this.indentSpaces), StringUtils.LF);

    CrigttPrettyPrinter prettyPrinter = new CrigttPrettyPrinter(indenter.getIndent());
    prettyPrinter.indentArraysWith(indenter);
    prettyPrinter.indentObjectsWith(indenter);

    this.getObject().setDefaultPrettyPrinter(prettyPrinter);
}
 
开发者ID:esacinc,项目名称:crigtt,代码行数:13,代码来源:CrigttObjectMapperFactoryBean.java

示例13: serialize

import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
private String serialize(JsonGraph jsonGraph) {
  DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter()
      .withObjectIndenter(new DefaultIndenter("  ", "\n"));

  ObjectWriter writer = this.objectMapper.writer(prettyPrinter);
  StringWriter jsonWriter = new StringWriter();
  try {
    writer.writeValue(jsonWriter, jsonGraph);
  } catch (IOException e) {
    // should never happen with StringWriter
    throw new IllegalStateException(e);
  }

  return jsonWriter.toString();
}
 
开发者ID:ferstl,项目名称:depgraph-maven-plugin,代码行数:16,代码来源:JsonGraphFormatter.java

示例14: StandardJsonPrettyPrinter

import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
public StandardJsonPrettyPrinter(String indent, String eol) {
    this.indent = indent;
    this.eol = eol;
    final DefaultIndenter indenter = new DefaultIndenter(indent, eol);
    this._arrayIndenter = indenter;
    this._objectIndenter = indenter;
}
 
开发者ID:vojtechhabarta,项目名称:typescript-generator,代码行数:8,代码来源:StandardJsonPrettyPrinter.java

示例15: SmartObjectMapper

import com.fasterxml.jackson.core.util.DefaultIndenter; //导入依赖的package包/类
/**
 * This constructor creates a new smart object mapper for the specified modules.
 *
 * @param modules The modules to be registered.
 */
SmartObjectMapper(Module... modules) {
    super();

    // indent the output
    enable(SerializationFeature.INDENT_OUTPUT);

    // allow empty beans
    disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);

    // don't serialize nulls
    disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
    setSerializationInclusion(Include.NON_NULL);

    // don't fail on unknown properties
    configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    // write dates out as string (not milliseconds since epoch <- timestamp)
    disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

    // handle joda types
    registerModule(new JodaModule());

    // handle primitive types that can generate strings
    addMixIn(craterdog.primitives.BinaryString.class, UseToStringAsValueMixIn.class);
    addMixIn(craterdog.primitives.Tag.class, UseToStringAsValueMixIn.class);
    addMixIn(craterdog.primitives.TextString.class, UseToStringAsValueMixIn.class);
    addMixIn(java.net.URI.class, UseToStringAsValueMixIn.class);

    // handle primitive types that can generate doubles
    addMixIn(craterdog.primitives.Angle.class, UseToDoubleAsValueMixIn.class);
    addMixIn(craterdog.primitives.Probability.class, UseToDoubleAsValueMixIn.class);

    // add any additional modules passed in
    for (Module module : modules) {
        registerModule(module);
    }

    setDefaultPrettyPrinter(new BetterPrettyPrinter().withArrayIndenter(new DefaultIndenter()));
}
 
开发者ID:craterdog,项目名称:java-smart-objects,代码行数:45,代码来源:SmartObjectMapper.java


注:本文中的com.fasterxml.jackson.core.util.DefaultIndenter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。