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.annotation.*; 019import org.apache.juneau.serializer.*; 020 021/** 022 * Serializes POJOs to HTTP responses as Java Serialized Object {@link ObjectOutputStream ObjectOutputStreams}. 023 * 024 * <h5 class='topic'>Media types</h5> 025 * 026 * Handles <c>Accept</c> types: <bc>application/x-java-serialized-object</bc> 027 * <p> 028 * Produces <c>Content-Type</c> types: <bc>application/x-java-serialized-object</bc> 029 */ 030@ConfigurableContext 031public class JsoSerializer extends OutputStreamSerializer { 032 033 //------------------------------------------------------------------------------------------------------------------- 034 // Configurable properties 035 //------------------------------------------------------------------------------------------------------------------- 036 037 static final String PREFIX = "JsoSerializer"; 038 039 //------------------------------------------------------------------------------------------------------------------- 040 // Predefined instances 041 //------------------------------------------------------------------------------------------------------------------- 042 043 /** Default serializer, all default settings.*/ 044 public static final JsoSerializer DEFAULT = new JsoSerializer(PropertyStore.DEFAULT); 045 046 //------------------------------------------------------------------------------------------------------------------- 047 // Instance 048 //------------------------------------------------------------------------------------------------------------------- 049 050 /** 051 * Constructor. 052 * 053 * @param ps The property store containing all the settings for this object. 054 */ 055 public JsoSerializer(PropertyStore ps) { 056 super(ps, "application/x-java-serialized-object", null); 057 } 058 059 @Override /* Context */ 060 public JsoSerializerBuilder builder() { 061 return new JsoSerializerBuilder(getPropertyStore()); 062 } 063 064 /** 065 * Instantiates a new clean-slate {@link JsoSerializerBuilder} object. 066 * 067 * <p> 068 * This is equivalent to simply calling <code><jk>new</jk> JsoSerializerBuilder()</code>. 069 * 070 * <p> 071 * Note that this method creates a builder initialized to all default settings, whereas {@link #builder()} copies 072 * the settings of the object called on. 073 * 074 * @return A new {@link JsoSerializerBuilder} object. 075 */ 076 public static JsoSerializerBuilder create() { 077 return new JsoSerializerBuilder(); 078 } 079 080 @Override /* Context */ 081 public JsoSerializerSession createSession() { 082 return createSession(createDefaultSessionArgs()); 083 } 084 085 @Override /* Serializer */ 086 public JsoSerializerSession createSession(SerializerSessionArgs args) { 087 return new JsoSerializerSession(this, args); 088 } 089 090 //----------------------------------------------------------------------------------------------------------------- 091 // Other methods 092 //----------------------------------------------------------------------------------------------------------------- 093 094 @Override /* Context */ 095 public ObjectMap toMap() { 096 return super.toMap() 097 .append("JsoSerializer", new DefaultFilteringObjectMap() 098 ); 099 } 100}