001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.jso;
014
015import java.io.*;
016
017import org.apache.juneau.*;
018import org.apache.juneau.serializer.*;
019
020/**
021 * Serializes POJOs to HTTP responses as Java Serialized Object {@link ObjectOutputStream ObjectOutputStreams}.
022 *
023 * <h5 class='topic'>Media types</h5>
024 *
025 * Handles <code>Accept</code> types:  <code><b>application/x-java-serialized-object</b></code>
026 * <p>
027 * Produces <code>Content-Type</code> types:  <code><b>application/x-java-serialized-object</b></code>
028 */
029public class JsoSerializer extends OutputStreamSerializer {
030
031   //-------------------------------------------------------------------------------------------------------------------
032   // Predefined instances
033   //-------------------------------------------------------------------------------------------------------------------
034
035   /** Default serializer, all default settings.*/
036   public static final JsoSerializer DEFAULT = new JsoSerializer(PropertyStore.DEFAULT);
037
038
039   //-------------------------------------------------------------------------------------------------------------------
040   // Instance
041   //-------------------------------------------------------------------------------------------------------------------
042
043   /**
044    * Constructor.
045    *
046    * @param ps The property store containing all the settings for this object.
047    */
048   public JsoSerializer(PropertyStore ps) {
049      super(ps, "application/x-java-serialized-object", null);
050   }
051
052   @Override /* Context */
053   public JsoSerializerBuilder builder() {
054      return new JsoSerializerBuilder(getPropertyStore());
055   }
056
057   /**
058    * Instantiates a new clean-slate {@link JsoSerializerBuilder} object.
059    *
060    * <p>
061    * This is equivalent to simply calling <code><jk>new</jk> JsoSerializerBuilder()</code>.
062    *
063    * <p>
064    * Note that this method creates a builder initialized to all default settings, whereas {@link #builder()} copies
065    * the settings of the object called on.
066    *
067    * @return A new {@link JsoSerializerBuilder} object.
068    */
069   public static JsoSerializerBuilder create() {
070      return new JsoSerializerBuilder();
071   }
072
073   @Override /* Serializer */
074   public OutputStreamSerializerSession createSession(SerializerSessionArgs args) {
075      return new JsoSerializerSession(this, args);
076   }
077}