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

org.grails.web.converters.Converter Maven / Gradle / Ivy

There is a newer version: 2023.0.2
Show newest version
/*
 * Copyright 2006-2022 the original author or authors.
 *
 * 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
 *
 *      https://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 org.grails.web.converters;

import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import groovy.lang.Closure;

import org.grails.web.converters.exceptions.ConverterException;
import org.grails.web.converters.marshaller.ObjectMarshaller;

/**
 * Defines an Object that can convert an instance and render it to the
 * response or a supplied writer.
 *
 * @author Siegfried Puchbauer
 */
public interface Converter {

    String DEFAULT_REQUEST_ENCODING = "UTF-8";

    /**
     * Marshalls the target and writes it to a java.io.Writer
     *
     * @param out The Writer to write to
     * @throws ConverterException
     */
    void render(Writer out) throws ConverterException;

    /**
     * Marshalls the target and writes it a HttpServletResponse
     * The response will be comitted after this operation
     *
     * @param response The response to write to
     * @throws ConverterException
     */
    void render(HttpServletResponse response) throws ConverterException;

    W getWriter() throws ConverterException;

    void convertAnother(Object o) throws ConverterException;

    void build(@SuppressWarnings("rawtypes") Closure c) throws ConverterException;

    @SuppressWarnings("rawtypes")
    ObjectMarshaller lookupObjectMarshaller(Object target);

    enum CircularReferenceBehaviour {
        DEFAULT,
        EXCEPTION,
        INSERT_NULL,
        IGNORE,
        PATH;

        public static List allowedValues() {
            List v = new ArrayList<>();
            for (CircularReferenceBehaviour crb : values()) {
                v.add(crb.name());
            }
            return v;
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy