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

com.tangosol.coherence.management.internal.MapProvider Maven / Gradle / Ivy

/*
 * Copyright (c) 2000, 2022, Oracle and/or its affiliates.
 *
 * Licensed under the Universal Permissive License v 1.0 as shown at
 * https://oss.oracle.com/licenses/upl.
 */
package com.tangosol.coherence.management.internal;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.tangosol.net.management.MapJsonBodyHandler;

import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.WebApplicationException;

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

import jakarta.ws.rs.ext.MessageBodyReader;
import jakarta.ws.rs.ext.MessageBodyWriter;
import jakarta.ws.rs.ext.Provider;

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

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * A {@link MessageBodyWriter} and {@link MessageBodyReader} for {@link Map}
 * or {@link LinkedHashMap}.
 * 

* When converting json to a {@link Map} this class will produce instances * of {@link LinkedHashMap}. * * @author jk 2019.05.31 */ @Provider @Produces({MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_JSON}) public class MapProvider implements MessageBodyWriter>, MessageBodyReader> { // ----- MessageBodyWriter methods -------------------------------------- @Override public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { return Map.class.equals(type) || LinkedHashMap.class.equals(type); } @Override public long getSize(Map map, Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { return 0; } @Override @SuppressWarnings("unchecked") public void writeTo(Map map, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { f_handler.write((Map) map, entityStream); } // ----- MessageBodyReader methods -------------------------------------- @Override public boolean isReadable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) { return Map.class.equals(type) || LinkedHashMap.class.equals(type); } @Override public Map readFrom(Class> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { return f_handler.readMap(entityStream); } // ----- constants ------------------------------------------------------ /** * The {@link ObjectMapper} to use to marshall {@link Map}s to and from json. */ private static final MapJsonBodyHandler f_handler = MapJsonBodyHandler.ensureMapJsonBodyHandler(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy