public void writeField ( Object object , String fieldName , String jsonName , Class elementType ) { Class type = object . getClass ( ) ; ObjectMap < String , FieldMetadata > fields = getFields ( type ) ; FieldMetadata metadata = fields . get ( fieldName ) ; if ( metadata == null ) throw new JsonException ( "Field not found: " + fieldName + " (" + type . getName ( ) + ")" ) ; Field field = metadata . field ; if ( elementType == null ) elementType = metadata . elementType ; try { if ( debug ) System . out . println ( "Writing field: " + field . getName ( ) + " (" + type . getName ( ) + ")" ) ; writer . name ( jsonName ) ; writeValue ( field . get ( object ) , field . getType ( ) , elementType ) ; } catch ( IllegalAccessException ex ) { throw new JsonException ( "Error accessing field: " + field . getName ( ) + " (" + type . getName ( ) + ")" , ex ) ; } catch ( JsonException ex ) { ex . addTrace ( field + " (" + type . getName ( ) + ")" ) ; throw ex ; } catch ( Exception runtimeEx ) { JsonException ex = new JsonException ( runtimeEx ) ; ex . addTrace ( field + " (" + type . getName ( ) + ")" ) ; throw ex ; } }
Writes the specified field to the current JSON object .