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

com.comcast.drivethru.spring.YamlCerealHttpMessageConverter Maven / Gradle / Ivy

There is a newer version: 2.0.7
Show newest version
/**
 * Copyright 2013 Comcast Cable Communications Management, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.comcast.drivethru.spring;


import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import com.comcast.cereal.engines.YamlCerealEngine;

/**
 * A {@link HttpMessageConverter} that can be used with spring that will do the internal conversion
 * using a {@link YamlCerealEngine}. When configured, this will convert all {@link ResponseBody} and
 * {@link RequestBody} objects that use the content type of "application/yaml".
 *
 * 

* To use this in a spring web application, simply add this code to your * app-context.xml: *

* *
 *   <mvc:annotation-driven>
 *     <mvc:message-converters register-defaults="false">
 *       <bean class="com.comcast.tvx.megahttp.spring.YamlCerealHttpMessageConverter" />
 *     </mvc:message-converters>
 *   </mvc:annotation-driven>
 * 
* *

* To configure to use an existing (and shared) {@link YamlCerealEngine} named "yamlEngine", use the * following configuration pattern: *

* *
 *   <mvc:annotation-driven>
 *     <mvc:message-converters register-defaults="false">
 *       <bean class="com.comcast.tvx.megahttp.spring.YamlCerealHttpMessageConverter">
 *         <constructor-arg index="0" ref="yamlEngine" />
 *       </bean>
 *     </mvc:message-converters>
 *   </mvc:annotation-driven>
 * 
* * @see MediaType#APPLICATION_JSON * * @author Clark Malmgren */ public class YamlCerealHttpMessageConverter extends AbstractCerealHttpMessageConverter { /** * Default constructor that will use a new {@link YamlCerealEngine} without block flow to * conserve size. */ public YamlCerealHttpMessageConverter() { this(new YamlCerealEngine(false)); } /** * Construct a new {@link YamlCerealHttpMessageConverter} that will delegate to the given * engine. * * @param engine * the engine to delegate to */ public YamlCerealHttpMessageConverter(YamlCerealEngine engine) { super(engine, MediaType.parseMediaType("application/yaml")); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy