Example usage for com.fasterxml.jackson.core JsonGenerator getPrettyPrinter

List of usage examples for com.fasterxml.jackson.core JsonGenerator getPrettyPrinter

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonGenerator getPrettyPrinter.

Prototype

public PrettyPrinter getPrettyPrinter() 

Source Link

Document

Accessor for checking whether this generator has a configured PrettyPrinter ; returns it if so, null if none configured.

Usage

From source file:ch.ralscha.extdirectspring.util.MapActionSerializer.java

@Override
public void serialize(Map<String, List<Action>> value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException {
    if (null != value) {
        jgen.writeStartObject();/* w ww  .ja  va  2 s.  com*/
        for (Entry<String, List<Action>> entry : value.entrySet()) {
            String key = entry.getKey();
            jgen.writeArrayFieldStart(key);
            List<Action> actions = entry.getValue();
            for (Action action : actions) {
                // PrettyPrinter is not set the generator is on one line
                // mode
                if (jgen.getPrettyPrinter() != null && action instanceof ActionDoc) {// insertion
                    // of
                    // doc
                    // here
                    ActionDoc actionDoc = (ActionDoc) action;
                    jgen.writeRaw("\n\t/**");
                    if (actionDoc.isDeprecated()) {
                        jgen.writeRaw("\n\t* @deprecated");
                    }
                    jgen.writeRaw("\n\t* " + actionDoc.getName() + ": " + actionDoc.getMethodComment());
                    jgen.writeRaw("\n\t* @author: " + actionDoc.getAuthor());
                    jgen.writeRaw("\n\t* @version: " + actionDoc.getVersion());
                    jgen.writeRaw("\n\t*");
                    for (Entry<String, String> entry2 : actionDoc.getParameters().entrySet()) {
                        jgen.writeRaw("\n\t* @param: [" + entry2.getKey() + "] " + entry2.getValue());
                    }
                    jgen.writeRaw("\n\t* @return");
                    for (Entry<String, String> entry2 : actionDoc.getReturnMethod().entrySet()) {
                        jgen.writeRaw("\n\t*\t [" + entry2.getKey() + "] " + entry2.getValue());
                    }
                    jgen.writeRaw("\n\t*/\n");
                }
                jgen.writeObject(action);
            }
            jgen.writeEndArray();
        }
        jgen.writeEndObject();
    }
}