protected void _writeSimpleObject ( Object value ) throws IOException , JsonGenerationException { /* 31-Dec-2009, tatu: Actually, we could just handle some basic * types even without codec. This can improve interoperability, * and specifically help with TokenBuffer. */ if ( value == null ) { writeNull ( ) ; return ; } if ( value instanceof String ) { writeString ( ( String ) value ) ; return ; } if ( value instanceof Number ) { Number n = ( Number ) value ; if ( n instanceof Integer ) { writeNumber ( n . intValue ( ) ) ; return ; } else if ( n instanceof Long ) { writeNumber ( n . longValue ( ) ) ; return ; } else if ( n instanceof Double ) { writeNumber ( n . doubleValue ( ) ) ; return ; } else if ( n instanceof Float ) { writeNumber ( n . floatValue ( ) ) ; return ; } else if ( n instanceof Short ) { writeNumber ( n . shortValue ( ) ) ; return ; } else if ( n instanceof Byte ) { writeNumber ( n . byteValue ( ) ) ; return ; } else if ( n instanceof BigInteger ) { writeNumber ( ( BigInteger ) n ) ; return ; } else if ( n instanceof BigDecimal ) { writeNumber ( ( BigDecimal ) n ) ; return ; // then Atomic types } else if ( n instanceof AtomicInteger ) { writeNumber ( ( ( AtomicInteger ) n ) . get ( ) ) ; return ; } else if ( n instanceof AtomicLong ) { writeNumber ( ( ( AtomicLong ) n ) . get ( ) ) ; return ; } } else if ( value instanceof Boolean ) { writeBoolean ( ( ( Boolean ) value ) . booleanValue ( ) ) ; return ; } else if ( value instanceof AtomicBoolean ) { writeBoolean ( ( ( AtomicBoolean ) value ) . get ( ) ) ; return ; } throw new IllegalStateException ( "No ObjectCodec defined for the generator, can only serialize simple wrapper types (type passed " + value . getClass ( ) . getName ( ) + ")" ) ; }
Helper method to try to call appropriate write method for given untyped Object . At this point no structural conversions should be done only simple basic types are to be coerced as necessary .