001/*
002 * (C) Copyright 2006-2010 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bstefanescu
018 */
019package org.nuxeo.ecm.automation.jaxrs;
020
021import java.io.IOException;
022import java.io.OutputStream;
023
024/**
025 * Should be implemented by objects that needs to be returned in response to clients as JSOn objects
026 * <p>
027 * Implementors are encouraged to use jackson JSON library since it is the one used by automation.
028 * <p>
029 * Also <b>note</b> that the JSON format for an object must follow the following schema:
030 *
031 * <pre>
032 * {
033 *   "entity-type": "typeName"
034 *   "value": { the marshalled object }
035 * }
036 * </pre>
037 *
038 * The value is either a scalar value (from primitive types) either a JSON object <code>{ ... }</code> The type name is
039 * the full class name of the serialized object. The primitive types are mapped to a short name as following:
040 * <ul>
041 * <li>string
042 * <li>date
043 * <li>boolean
044 * <li>long
045 * <li>double
046 * <li>null - this is a special type in case the objec is null - but this may never happens (since null objects are
047 * returning an empty content)
048 * </ul>
049 *
050 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
051 */
052public interface JsonAdapter {
053
054    void toJSON(OutputStream out) throws IOException;
055
056}