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.serializer; 014 015import static org.apache.juneau.common.internal.StringUtils.*; 016 017import org.apache.juneau.*; 018 019/** 020 * Class for listening for serialize events during a serialization. 021 * 022 * <h5 class='section'>See Also:</h5><ul> 023 * <li class='link'><a class="doclink" href="../../../../index.html#jm.SerializersAndParsers">Serializers and Parsers</a> 024 025 * </ul> 026 */ 027public class SerializerListener { 028 029 /** 030 * Represents no serializer listener. 031 */ 032 public static final class Void extends SerializerListener {} 033 034 /** 035 * Called when an exception is thrown when trying to call a bean getter method. 036 * 037 * @param session The serializer session. 038 * @param t The throwable that was thrown by the getter method. 039 * @param p The bean property we had an issue on. 040 */ 041 public void onBeanGetterException(SerializerSession session, Throwable t, BeanPropertyMeta p) { 042 onError(session, t, format("Could not call getValue() on property ''{0}'' of class ''{1}'', exception = {2}", 043 p.getName(), p.getBeanMeta().getClassMeta(), t.getLocalizedMessage())); 044 } 045 046 /** 047 * Called when an error occurs during serialization but is ignored. 048 * 049 * @param session The serializer session. 050 * @param t The throwable that was thrown by the getter method. 051 * @param msg The error message. 052 */ 053 public void onError(SerializerSession session, Throwable t, String msg) { 054 // Do something with this information. 055 } 056}