@Test public void deepCopyTest() throws IOException { Map<String, Object> testUnit = JsonUtils.classpathToMap( "/json/defaultr/__deepCopyTest.json" ); Object spec = testUnit.get( "spec" ); Defaultr defaultr = new Defaultr(spec); { Object input = testUnit.get( "input" ); Map<String, Object> fiddle = (Map<String, Object>) defaultr.transform( input ); List array = (List) fiddle.get( "array" ); array.add("a"); Map<String,Object> subMap = (Map<String,Object>) fiddle.get( "map" ); subMap.put("c", "c"); } { Map<String, Object> testUnit2 = JsonUtils.classpathToMap( "/json/defaultr/__deepCopyTest.json" ); Object input = testUnit2.get( "input" ); Object expected = testUnit2.get( "expected" ); Object actual = defaultr.transform( input ); JoltTestUtil.runDiffy( "Same spec deepcopy fail.", expected, actual ); } }
@Override public Object transform( Object input ) { if ( input == null ) { input = new HashMap(); } if ( input instanceof List ) { if ( arrayRoot == null ) { throw new TransformException( "The Spec provided can not handle input that is a top level Json Array." ); } arrayRoot.applyChildren( input ); } else { mapRoot.applyChildren( input ); } return input; }
Defaultr implements SpecDriven, Transform { @Override public Object transform( Object input ) { if ( input == null ) { input = new HashMap(); } if ( input instanceof List ) { if ( arrayRoot == null ) { throw new TransformException( "The Spec provided can not handle input that is a top level Json Array." ); } arrayRoot.applyChildren( input ); } else { mapRoot.applyChildren( input ); } return input; } }
Defaultr implements SpecDriven, Transform { @Override public Object transform( Object input ) { if ( input == null ) { input = new HashMap(); } if ( input instanceof List ) { if ( arrayRoot == null ) { throw new TransformException( "The Spec provided can not handle input that is a top level Json Array." ); } arrayRoot.applyChildren( input ); } else { mapRoot.applyChildren( input ); } return input; } @Inject  Defaultr( Object spec ); }
Defaultr implements SpecDriven, Transform { @Override public Object transform( Object input ) { if ( input == null ) { input = new HashMap(); } if ( input instanceof List ) { if ( arrayRoot == null ) { throw new TransformException( "The Spec provided can not handle input that is a top level Json Array." ); } arrayRoot.applyChildren( input ); } else { mapRoot.applyChildren( input ); } return input; } @Inject  Defaultr( Object spec ); @Override Object transform( Object input ); }
Defaultr implements SpecDriven, Transform { @Override public Object transform( Object input ) { if ( input == null ) { input = new HashMap(); } if ( input instanceof List ) { if ( arrayRoot == null ) { throw new TransformException( "The Spec provided can not handle input that is a top level Json Array." ); } arrayRoot.applyChildren( input ); } else { mapRoot.applyChildren( input ); } return input; } @Inject  Defaultr( Object spec ); @Override Object transform( Object input );  }