private static < T > void setOriginField ( T hasOriginField , Class < T > clazz , ConfigOrigin origin ) throws IOException { // circumvent "final" Field f ; try { f = clazz . getDeclaredField ( "origin" ) ; } catch ( NoSuchFieldException e ) { throw new IOException ( clazz . getSimpleName ( ) + " has no origin field?" , e ) ; } catch ( SecurityException e ) { throw new IOException ( "unable to fill out origin field in " + clazz . getSimpleName ( ) , e ) ; } f . setAccessible ( true ) ; try { f . set ( hasOriginField , origin ) ; } catch ( IllegalArgumentException e ) { throw new IOException ( "unable to set origin field" , e ) ; } catch ( IllegalAccessException e ) { throw new IOException ( "unable to set origin field" , e ) ; } }
For deserialization - uses reflection to set the final origin field on the object