package com.cloudera.server.web.headlamp.hdfs;

import com.cloudera.enterprise.ThriftUtil;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import org.apache.thrift.TBase;
import org.apache.thrift.TException;

class ThriftToJacksonSerializer extends JsonSerializer<TBase<?, ?>>
{
  public void serialize(TBase<?, ?> value, JsonGenerator jgen, SerializerProvider provider)
    throws IOException, JsonProcessingException
  {
    try
    {
      String json = ThriftUtil.thriftToJson(value);
      jgen.writeRawValue(json);
    } catch (TException e) {
      throw new JsonGenerationException(e);
    }
  }
}