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

com.pkulak.httpclient.mapper.JacksonRequestMapper Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package com.pkulak.httpclient.mapper;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

public class JacksonRequestMapper implements RequestMapper {
    private static final String CONTENT_TYPE = "application/json";

    private final ObjectMapper mapper;

    public JacksonRequestMapper(ObjectMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public InputStream map(Object object) throws JsonProcessingException {
        return new ByteArrayInputStream(mapper.writeValueAsBytes(object));
    }

    @Override
    public String defaultContentType() {
        return CONTENT_TYPE;
    }
}