static void forceWritingEnumValue ( VerboseXmlEncoder encoder , Object object ) { Field valueToExpressionField = null ; Field refsField = null ; try { Class < ? > encoderClass = encoder . getClass ( ) . getSuperclass ( ) ; valueToExpressionField = encoderClass . getDeclaredField ( "valueToExpression" ) ; valueToExpressionField . setAccessible ( true ) ; Object valueToExpressionObject = valueToExpressionField . get ( encoder ) ; Map < ? , ? > valueToExpression = ( Map < ? , ? > ) valueToExpressionObject ; Object valueData = valueToExpression . get ( object ) ; if ( valueData != null ) { Class < ? > valueDataClass = valueData . getClass ( ) ; refsField = valueDataClass . getDeclaredField ( "refs" ) ; refsField . setAccessible ( true ) ; refsField . setInt ( valueData , 0 ) ; } } catch ( NoSuchFieldException e ) { logger . warning ( e . toString ( ) ) ; } catch ( SecurityException e ) { logger . warning ( e . toString ( ) ) ; } catch ( IllegalArgumentException e ) { logger . warning ( e . toString ( ) ) ; } catch ( IllegalAccessException e ) { logger . warning ( e . toString ( ) ) ; } finally { if ( valueToExpressionField != null ) { valueToExpressionField . setAccessible ( false ) ; } if ( refsField != null ) { refsField . setAccessible ( false ) ; } } }
Use a nasty reflection hack to make sure that the given object is always written explicitly without using idref in the given VerboseXmlEncoder