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