001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.marshall.swap.spi;
018
019import org.apache.juneau.marshall.collections.*;
020
021/**
022 * Abstract subclass for object swaps that swap objects for object maps.
023 *
024 * <h5 class='section'>Example:</h5>
025 * <p class='bjava'>
026 *    <jc>// A swap that converts beans into generic maps.</jc>
027 *    <jk>public class</jk> MyBeanSwap <jk>extends</jk> MapSwap&lt;<jk>byte</jk>[]&gt; {
028 *
029 *       <ja>@Override</ja>
030 *       <jk>public</jk> JsonMap swap(MarshallingSession <jv>session</jv>, MyBean <jv>bean</jv>) <jk>throws</jk> Exception {
031 *          <jk>return</jk> JsonMap.<jsm>of</jsm>(<js>"foo"</js>, <jv>bean</jv>.getFoo());
032 *       }
033 *
034 *       <ja>@Override</ja>
035 *       <jk>public</jk> MyBean unswap(MarshallingSession <jv>session</jv>, JsonMap <jv>map</jv>, ClassMeta&lt;?&gt; <jv>hint</jv>) <jk>throws</jk> Exception {
036 *          <jk>return</jk> <jk>new</jk> MyBean(<jv>map</jv>.get(<js>"foo"</js>));
037 *       }
038 *    }
039 *
040 *    <jc>// Use it to serialize a byte array.</jc>
041 *    WriterSerializer <jv>serializer</jv> = Json5Serializer.<jsm>create</jsm>().swaps(MyBeanSwap.<jk>class</jk>).build();
042 *    String <jv>json</jv> = <jv>serializer</jv>.write(<jk>new</jk> MyBean(<js>"bar"</js>));  <jc>// Produces "{foo:'bar'}"</jc>
043 * </p>
044 *
045 * <h5 class='section'>See Also:</h5><ul>
046 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Swaps">Swap</a>
047 * </ul>
048 *
049 * @param <T> The normal form of the class.
050 */
051public abstract class MapSwap<T> extends ObjectSwap<T,JsonMap> {
052}