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

com.github.pgelinas.jackson.javax.json.JacksonWriterFactory Maven / Gradle / Ivy

Go to download

An alternate implementation of JSR-353 based on Jackson, which aims to bring better performance and configurability.

The newest version!
package com.github.pgelinas.jackson.javax.json;

import java.io.*;
import java.nio.charset.*;
import java.util.*;

import javax.json.*;

import com.fasterxml.jackson.databind.*;

public class JacksonWriterFactory implements JsonWriterFactory {
    private final ObjectMapper _mapper;
    private Map _configInUse;

    public JacksonWriterFactory(Map config) {
        this(new ObjectMapper());
        _configInUse = ConfigurationUtils.configure(_mapper, config);
    }

    public JacksonWriterFactory(ObjectMapper mapper) {
        _mapper = mapper;
    }

    @Override
    public JsonWriter createWriter(Writer writer) {
        try {
            return new JacksonWriter(_mapper, writer);
        } catch (IOException exception) {
            throw new JsonException("", exception);
        }
    }

    @Override
    public JsonWriter createWriter(OutputStream out) {
        try {
            return new JacksonWriter(_mapper, out);
        } catch (IOException exception) {
            throw new JsonException("", exception);
        }
    }

    @Override
    public JsonWriter createWriter(OutputStream out, Charset charset) {
        return createWriter(new OutputStreamWriter(out, charset));
    }

    @Override
    public Map getConfigInUse() {
        return _configInUse;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy