@Test public void convertWithNullList() { CustomerV2 customer = converter.convertToHigherVersion(CustomerV2.class, new CustomerV1() {{ name = "customer"; dateOfBirth = "01/01/1970"; addresses = null; }}, "v1"); assertThat(customer.getName(), is("customer")); assertThat(customer.getDateOfBirth(), is(new Date(0))); assertThat(customer.getAddresses(), is(nullValue())); }
public <T> T convertToHigherVersion(Class<T> targetType, Object source, String sourceVersion) { SupportedVersion supportedVersion = targetType.getAnnotation(SupportedVersion.class); if (supportedVersion == null) { throw new IllegalVersionException(sourceVersion); } if (supportedVersion.version().equals(sourceVersion)) { mapper.map(source); return targetType.cast(source); } if (supportedVersion.previous() == Object.class) { throw new IllegalVersionException(sourceVersion); } Object previousVersion = convertToHigherVersion(supportedVersion.previous(), source, sourceVersion); return map(previousVersion, targetType, new DefaultVersionContext()); }
InterversionConverter { public <T> T convertToHigherVersion(Class<T> targetType, Object source, String sourceVersion) { SupportedVersion supportedVersion = targetType.getAnnotation(SupportedVersion.class); if (supportedVersion == null) { throw new IllegalVersionException(sourceVersion); } if (supportedVersion.version().equals(sourceVersion)) { mapper.map(source); return targetType.cast(source); } if (supportedVersion.previous() == Object.class) { throw new IllegalVersionException(sourceVersion); } Object previousVersion = convertToHigherVersion(supportedVersion.previous(), source, sourceVersion); return map(previousVersion, targetType, new DefaultVersionContext()); } }
InterversionConverter { public <T> T convertToHigherVersion(Class<T> targetType, Object source, String sourceVersion) { SupportedVersion supportedVersion = targetType.getAnnotation(SupportedVersion.class); if (supportedVersion == null) { throw new IllegalVersionException(sourceVersion); } if (supportedVersion.version().equals(sourceVersion)) { mapper.map(source); return targetType.cast(source); } if (supportedVersion.previous() == Object.class) { throw new IllegalVersionException(sourceVersion); } Object previousVersion = convertToHigherVersion(supportedVersion.previous(), source, sourceVersion); return map(previousVersion, targetType, new DefaultVersionContext()); } InterversionConverter(VersionTypeFactory factory, CompatibilityMapper mapper); }
InterversionConverter { public <T> T convertToHigherVersion(Class<T> targetType, Object source, String sourceVersion) { SupportedVersion supportedVersion = targetType.getAnnotation(SupportedVersion.class); if (supportedVersion == null) { throw new IllegalVersionException(sourceVersion); } if (supportedVersion.version().equals(sourceVersion)) { mapper.map(source); return targetType.cast(source); } if (supportedVersion.previous() == Object.class) { throw new IllegalVersionException(sourceVersion); } Object previousVersion = convertToHigherVersion(supportedVersion.previous(), source, sourceVersion); return map(previousVersion, targetType, new DefaultVersionContext()); } InterversionConverter(VersionTypeFactory factory, CompatibilityMapper mapper); T convertToLowerVersion(String targetVersion, Object source); T convertToHigherVersion(Class<T> targetType, Object source, String sourceVersion); }
InterversionConverter { public <T> T convertToHigherVersion(Class<T> targetType, Object source, String sourceVersion) { SupportedVersion supportedVersion = targetType.getAnnotation(SupportedVersion.class); if (supportedVersion == null) { throw new IllegalVersionException(sourceVersion); } if (supportedVersion.version().equals(sourceVersion)) { mapper.map(source); return targetType.cast(source); } if (supportedVersion.previous() == Object.class) { throw new IllegalVersionException(sourceVersion); } Object previousVersion = convertToHigherVersion(supportedVersion.previous(), source, sourceVersion); return map(previousVersion, targetType, new DefaultVersionContext()); } InterversionConverter(VersionTypeFactory factory, CompatibilityMapper mapper); T convertToLowerVersion(String targetVersion, Object source); T convertToHigherVersion(Class<T> targetType, Object source, String sourceVersion);  }