Example usage for com.fasterxml.jackson.dataformat.xml XmlMapper writerWithDefaultPrettyPrinter

List of usage examples for com.fasterxml.jackson.dataformat.xml XmlMapper writerWithDefaultPrettyPrinter

Introduction

In this page you can find the example usage for com.fasterxml.jackson.dataformat.xml XmlMapper writerWithDefaultPrettyPrinter.

Prototype

public ObjectWriter writerWithDefaultPrettyPrinter() 

Source Link

Document

Factory method for constructing ObjectWriter that will serialize objects using the default pretty printer for indentation

Usage

From source file:com.blockwithme.lessobjects.util.JSONParser.java

/**
 * To xml string./*from   w w  w  .j ava 2s  . c  o  m*/
 *
 * @return the string
 */
@SuppressWarnings("null")
public String toXMLString() {

    if (xmlString == null) {
        if (!fromSchema) {
            try {
                final XmlMapper mapper = new XmlMapper();
                xmlString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
            } catch (final JsonProcessingException jpe) {
                throw new IllegalStateException(jpe.getMessage(), jpe);
            }
        } else {
            try {
                if (format == SchemaFormat.JSON) {
                    if (jsonString == null) {
                        jsonString = jsonOrXMLString;
                    }
                    schema = getBinding();
                    xmlString = new XmlMapper().writerWithDefaultPrettyPrinter().writeValueAsString(schema);
                } else {
                    xmlString = jsonOrXMLString;
                }
            } catch (final IOException e) {
                throw new IllegalStateException(e.getMessage(), e);
            }
        }
    }
    return xmlString;
}