public static FieldMarshaller getFieldMarshaller ( Field field ) { if ( _marshallers == null ) { // multiple threads may attempt to create the stock marshallers, but they'll just do // extra work and _marshallers will only ever contain a fully populated table _marshallers = createMarshallers ( ) ; } // if necessary (we're running in a sandbox), look for custom field accessors if ( useFieldAccessors ( ) ) { Method reader = null , writer = null ; try { reader = field . getDeclaringClass ( ) . getMethod ( getReaderMethodName ( field . getName ( ) ) , READER_ARGS ) ; } catch ( NoSuchMethodException nsme ) { // no problem } try { writer = field . getDeclaringClass ( ) . getMethod ( getWriterMethodName ( field . getName ( ) ) , WRITER_ARGS ) ; } catch ( NoSuchMethodException nsme ) { // no problem } if ( reader != null && writer != null ) { return new MethodFieldMarshaller ( reader , writer ) ; } if ( ( reader == null && writer != null ) || ( writer == null && reader != null ) ) { log . warning ( "Class contains one but not both custom field reader and writer" , "class" , field . getDeclaringClass ( ) . getName ( ) , "field" , field . getName ( ) , "reader" , reader , "writer" , writer ) ; // fall through to using reflection on the fields... } } Class < ? > ftype = field . getType ( ) ; // use the intern marshaller for pooled strings if ( ftype == String . class && field . isAnnotationPresent ( Intern . class ) ) { return _internMarshaller ; } // if we have an exact match, use that FieldMarshaller fm = _marshallers . get ( ftype ) ; if ( fm == null ) { Class < ? > collClass = Streamer . getCollectionClass ( ftype ) ; if ( collClass != null && ! collClass . equals ( ftype ) ) { log . warning ( "Specific field types are discouraged " + "for Iterables/Collections and Maps. The implementation type may not be " + "recreated on the other side." , "class" , field . getDeclaringClass ( ) , "field" , field . getName ( ) , "type" , ftype , "shouldBe" , collClass ) ; fm = _marshallers . get ( collClass ) ; } // otherwise if the class is a pure interface or streamable, // use the streamable marshaller if ( fm == null && ( ftype . isInterface ( ) || Streamer . isStreamable ( ftype ) ) ) { fm = _marshallers . get ( Streamable . class ) ; } } return fm ; }
Returns a field marshaller appropriate for the supplied field or null if no marshaller exists for the type contained by the field in question .