com.fasterxml.jackson.module.jakarta.xmlbind.deser.DataHandlerDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-module-jakarta-xmlbind-annotations Show documentation
Show all versions of jackson-module-jakarta-xmlbind-annotations Show documentation
Support for using Jakarta XML Bind (aka JAXB 3.0) annotations as an alternative
to "native" Jackson annotations, for configuring data-binding.
The newest version!
package com.fasterxml.jackson.module.jakarta.xmlbind.deser;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.ByteArrayInputStream;
import jakarta.activation.DataHandler;
import jakarta.activation.DataSource;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
public class DataHandlerDeserializer
extends StdScalarDeserializer
{
private static final long serialVersionUID = 1L;
public DataHandlerDeserializer() { super(DataHandler.class); }
@Override
public DataHandler deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException, JsonProcessingException
{
final byte[] value = p.getBinaryValue();
return new DataHandler(new DataSource() {
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(value);
}
@Override
public OutputStream getOutputStream() throws IOException {
throw new IOException();
}
@Override
public String getContentType() {
return "application/octet-stream";
}
@Override
public String getName() {
return "json-binary-data";
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy