Example usage for com.fasterxml.jackson.databind ObjectWriter withRootName

List of usage examples for com.fasterxml.jackson.databind ObjectWriter withRootName

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectWriter withRootName.

Prototype

public ObjectWriter withRootName(String rootName) 

Source Link

Document

Method for constructing a new instance with configuration that specifies what root name to use for "root element wrapping".

Usage

From source file:io.github.jdocker.common.vertx.JacksonCodec.java

@Override
public void encodeToWire(Buffer buffer, Object o) {
    ObjectWriter writer = mapper.writer();
    StringWriter w = new StringWriter();
    try {//from  ww w .j  av  a 2s  .c o  m
        writer.withRootName(o.getClass().getSimpleName()).writeValue(w, o);
        buffer.appendBytes(w.toString().getBytes());
    } catch (IOException e) {
        throw new IllegalStateException("Cannot serialize into json: " + o, e);
    }

}