com.fitbur.fasterxml.jackson.module.jaxb.deser.DataHandlerJsonDeserializer Maven / Gradle / Ivy
package com.fitbur.fasterxml.jackson.module.jaxb.com.fitburser;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.ByteArrayInputStream;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import com.fitbur.fasterxml.jackson.core.JsonParser;
import com.fitbur.fasterxml.jackson.core.JsonProcessingException;
import com.fitbur.fasterxml.jackson.databind.DeserializationContext;
import com.fitbur.fasterxml.jackson.databind.com.fitburser.std.StdScalarDeserializer;
/**
* @author Ryan Heaton
*/
public class DataHandlerJsonDeserializer
extends StdScalarDeserializer
{
public DataHandlerJsonDeserializer() { super(DataHandler.class); }
@Override
public DataHandler com.fitburserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
final byte[] value = jp.getBinaryValue();
return new DataHandler(new DataSource() {
public InputStream getInputStream() throws IOException
{
return new ByteArrayInputStream(value);
}
public OutputStream getOutputStream() throws IOException
{
throw new IOException();
}
public String getContentType()
{
return "application/octet-stream";
}
public String getName()
{
return "json-binary-data";
}
});
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy