public Object put ( Object key , Object value ) { if ( null == key ) throw new IllegalArgumentException ( "key must not be null" ) ; if ( ! ( key instanceof String ) ) throw new IllegalArgumentException ( "key must be a String" ) ; if ( ! isValidObject ( value ) ) { if ( value != null ) { throw new IllegalArgumentException ( "Invalid type of value. Type: [" + value . getClass ( ) . getName ( ) + "] with value: [" + value . toString ( ) + "]" ) ; } else { throw new IllegalArgumentException ( "Invalid type of value." ) ; } } /** * Only put it in the ordering list if it isn't already present. */ if ( ! this . containsKey ( key ) ) { this . order . add ( key ) ; } return super . put ( key , value ) ; }
Method to put a JSON able object into the instance . Note that the order of initial puts controls the order of serialization . Meaning that the first time an item is put into the object determines is position of serialization . Subsequent puts with the same key replace the existing entry value and leave serialization position alone . For moving the position the object must be removed then re - put .