private JsonClassWriterBase forceGetCustomWriter ( Class c ) { JsonClassWriterBase closestWriter = nullWriter ; int minDistance = Integer . MAX_VALUE ; for ( Map . Entry < Class , JsonClassWriterBase > entry : writers . entrySet ( ) ) { Class clz = entry . getKey ( ) ; if ( clz == c ) { return entry . getValue ( ) ; } int distance = MetaUtils . getDistance ( clz , c ) ; if ( distance < minDistance ) { minDistance = distance ; closestWriter = entry . getValue ( ) ; } } return closestWriter ; }
Fetch the customer writer for the passed in Class . This method always fetches the custom writer doing the complicated inheritance distance checking . This method is only called when a cache miss has happened . A sentinal nullWriter is returned when no custom writer is found . This prevents future cache misses from re - attempting to find custom writers for classes that do not have a custom writer .