All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testifyproject.github.dockerjava.netty.handler.JsonRequestHandler Maven / Gradle / Ivy

package org.testifyproject.testifyproject.github.dockerjava.netty.handler;

import org.testifyproject.testifyproject.netty.buffer.ByteBuf;
import org.testifyproject.testifyproject.netty.channel.ChannelHandlerContext;
import org.testifyproject.testifyproject.netty.handler.codec.MessageToByteEncoder;

import org.testifyproject.testifyproject.fasterxml.jackson.databind.ObjectMapper;

/**
 * Handler that encodes an outgoing object to JSON.
 *
 * @author Marcus Linke
 */
public class JsonRequestHandler extends MessageToByteEncoder {

    private ObjectMapper mapper = new ObjectMapper();

    @Override
    protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
        byte[] serialized = mapper.writeValueAsBytes(msg);
        out.writeBytes(serialized);
    }
}