JAXBElementConverter implements Converter { public String getBeanId() { Class<?> factoryClass = objectFactory(destObjClass, beanContainer).getClass(); Class<?> destClass = null; String methodName = "create" + destObjClass.substring(destObjClass.lastIndexOf(".") + 1) + StringUtils.capitalize(destFieldName); try { Method method = ReflectionUtils.findAMethod(factoryClass, methodName, beanContainer); Class<?>[] parameterTypes = method.getParameterTypes(); for (Class<?> parameterClass : parameterTypes) { destClass = parameterClass; break; } } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); } return (destClass != null) ? destClass.getCanonicalName() : null; } JAXBElementConverter(String destObjClass, String destFieldName, DateFormat dateFormat, BeanContainer beanContainer); @Override Object convert(Class type, Object value); String getBeanId();  }
@Test public void stringTypeBeanId() { converter = new JAXBElementConverter(EmployeeWithInnerClass.class.getCanonicalName(), "parentName", new SimpleDateFormat("dd.MM.yyyy"), beanContainer); String beanId = converter.getBeanId(); assertNotNull(beanId); assertEquals("java.lang.String", beanId); }
@Test public void xmlgregoriancalendarTypeBeanId() { converter = new JAXBElementConverter(EmployeeType.class.getCanonicalName(), "birthDate", new SimpleDateFormat("dd.MM.yyyy"), beanContainer); String beanId = converter.getBeanId(); assertNotNull(beanId); assertEquals("javax.xml.datatype.XMLGregorianCalendar", beanId); }
@Test(expected = MappingException.class) public void beanIdFieldNotFoundException() { converter = new JAXBElementConverter(EmployeeWithInnerClass.class.getCanonicalName(), "vds", new SimpleDateFormat("dd.MM.yyyy"), beanContainer); converter.getBeanId(); }