@Test public void testResolveMapKeys() { PropertyResolverStrategy propertyResolver = UtilityResolver.getDefaultPropertyResolverStrategy(); Property namesFirst = propertyResolver.getProperty(PersonDto.class, "names['first']"); Assert.assertNotNull(namesFirst); Assert.assertEquals(TypeFactory.valueOf(String.class), namesFirst.getType()); Assert.assertNull(namesFirst.getContainer()); VariableRef ref = new VariableRef(namesFirst, "destination"); Assert.assertEquals( "((java.lang.String)((java.util.Map)destination.names).get(\"first\"))", ref.toString()); }
public String generateMappingCode( FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { if (code.isDebugEnabled()) { code.debug( "mapping Map<" + source.type().getNestedType(0) + ", " + source.type().getNestedType(1) + "> to " + destination.elementTypeName() + "[]"); } return super.generateMappingCode(fieldMap, entrySetRef(source), destination, code); }
@Override public String generateMappingCode( FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { StringBuilder sb = new StringBuilder(); sb.append( String.format("if(org.hibernate.Hibernate.isInitialized(%s)) {", source.asWrapper())); sb.append(delegate.generateMappingCode(fieldMap, source, destination, code)); sb.append("}\n"); return sb.toString(); }