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.marshall; 014 015import org.apache.juneau.parser.*; 016import org.apache.juneau.serializer.*; 017 018/** 019 * A subclass of {@link Marshall} for character-based serializers and parsers. 020 * 021 * <h5 class='section'>See Also:</h5> 022 * <ul> 023 * <li class='link'>{@doc juneau-marshall.Marshalls} 024 * </ul> 025 */ 026public abstract class CharMarshall extends Marshall { 027 028 private final WriterSerializer s; 029 030 /** 031 * Constructor. 032 * 033 * @param s 034 * The serializer to use for serializing output. 035 * <br>Must not be <jk>null</jk>. 036 * @param p 037 * The parser to use for parsing input. 038 * <br>Must not be <jk>null</jk>. 039 */ 040 protected CharMarshall(WriterSerializer s, ReaderParser p) { 041 super(s, p); 042 this.s = s; 043 } 044 045 /** 046 * Serializes a POJO directly to a <code>String</code>. 047 * 048 * @param o The object to serialize. 049 * @return 050 * The serialized object. 051 * @throws SerializeException If a problem occurred trying to convert the output. 052 */ 053 @Override /* Serializer */ 054 public final String write(Object o) throws SerializeException { 055 return s.createSession().serializeToString(o); 056 } 057}