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

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

Introduction

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

Prototype

public Object getOutputTarget() 

Source Link

Document

Method that can be used to get access to object that is used as target for generated output; this is usually either OutputStream or Writer , depending on what generator was constructed with.

Usage

From source file:org.webpda.server.core.servermessage.PingMessage.java

@Override
public String createJson() throws JsonProcessingException {
    try {//  w  w w .  j  a va 2  s .  c  om
        JsonGenerator jg = createJsonGenerator();
        jg.writeNumberField("Count", count);

        jg.writeEndObject();
        jg.close();
        ByteArrayOutputStream outputStream = (ByteArrayOutputStream) jg.getOutputTarget();
        String s = outputStream.toString(Constants.CHARSET);
        outputStream.close();
        return s;
    } catch (Exception e) {
        LoggerUtil.getLogger().log(Level.SEVERE, "Failed to create json.", e);
    }

    return null;
}

From source file:org.webpda.server.core.servermessage.ErrorMessage.java

@Override
public String createJson() throws JsonProcessingException {
    try {/*from w w w.  j a  v a 2  s .  c  o  m*/
        JsonGenerator jg = createJsonGenerator();
        jg.writeStringField("title", title);
        jg.writeStringField("details", details);
        jg.writeEndObject();
        jg.close();
        ByteArrayOutputStream outputStream = (ByteArrayOutputStream) jg.getOutputTarget();
        String s = outputStream.toString(Constants.CHARSET);
        outputStream.close();
        return s;
    } catch (Exception e) {
        LoggerUtil.getLogger().log(Level.SEVERE, "Failed to create json.", e);
    }

    return null;
}