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

com.google.sitebricks.client.transport.JacksonJsonTransport Maven / Gradle / Ivy

There is a newer version: 0.8.11
Show newest version
package com.google.sitebricks.client.transport;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.codehaus.jackson.map.ObjectMapper;

import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
 * @author Dhanji R. Prasanna ([email protected])
 */
@Singleton
public class JacksonJsonTransport extends Json {

  private final ObjectMapper objectMapper;

  @Inject
  public JacksonJsonTransport(ObjectMapper objectMapper) {
    this.objectMapper = objectMapper;
  }  
  
  public ObjectMapper getObjectMapper() {
    return objectMapper;
  }
  
  public  T in(InputStream in, Class type) throws IOException {
    return objectMapper.readValue(in, type);
  }

  public  void out(OutputStream out, Class type, T data) {
    try {
      objectMapper.writeValue(out, data);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy