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

com.tangosol.coherence.rest.io.JacksonJsonMarshaller Maven / Gradle / Ivy

There is a newer version: 24.09
Show newest version
/*
 * Copyright (c) 2000, 2020, Oracle and/or its affiliates.
 *
 * Licensed under the Universal Permissive License v 1.0 as shown at
 * http://oss.oracle.com/licenses/upl.
 */
package com.tangosol.coherence.rest.io;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.tangosol.coherence.rest.providers.JacksonMapperProvider;

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

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

/**
 * Jackson-based marshaller that marshals object to/from JSON.
 *
 * @author as  2011.07.13
 */
public class JacksonJsonMarshaller
        extends AbstractMarshaller
    {
    // ---- constructors ----------------------------------------------------

    /**
     * Construct JacksonJsonMarshaller instance.
     *
     * @param clzRoot  class of the root object this marshaller is for
     */
    public JacksonJsonMarshaller(Class clzRoot)
        {
        super(clzRoot);

        m_objectMapper = JacksonMapperProvider.getObjectMapper();
        }

    // ---- Marshaller implementation ---------------------------------------

    @Override
    public void marshal(T value, OutputStream out, MultivaluedMap httpHeaders) throws IOException
        {
        m_objectMapper.writeValue(out, value);
        }

    @Override
    public T unmarshal(InputStream in, MediaType mediaType) throws IOException
        {
        return m_objectMapper.readValue(in, getRootClass());
        }

    // ---- data members ----------------------------------------------------

    /**
     * Object mapper to use for marshalling.
     */
    private final ObjectMapper m_objectMapper;
    }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy