@Test public void convertCustomerFromV2ToV1() { CustomerV1 customer = converter.convertToLowerVersion("v1", new CustomerV2("customer", new Date(0), new AddressV2("Samplestreet 1", " ", new CityV2("12345", "Samplecity")))); assertThat(customer.getName(), is("customer")); assertThat(customer.getDateOfBirth(), is("Thu Jan 01 00:00:00 GMT 1970")); assertThat(customer.getAddresses().size(), is(1)); assertThat(customer.getAddresses(), hasItem(v10())); }
public <T> T convertToLowerVersion(String targetVersion, Object source) { Class<?> sourceType = source.getClass(); SupportedVersion supportedVersion = sourceType.getAnnotation(SupportedVersion.class); if (supportedVersion == null) { throw new IllegalVersionException(targetVersion); } if (targetVersion.equals(supportedVersion.version())) { return (T)source; } if (supportedVersion.previous() == Object.class) { throw new IllegalVersionException(targetVersion); } return convertToLowerVersion(targetVersion, map(source, supportedVersion.previous(), new DefaultVersionContext())); }
InterversionConverter { public <T> T convertToLowerVersion(String targetVersion, Object source) { Class<?> sourceType = source.getClass(); SupportedVersion supportedVersion = sourceType.getAnnotation(SupportedVersion.class); if (supportedVersion == null) { throw new IllegalVersionException(targetVersion); } if (targetVersion.equals(supportedVersion.version())) { return (T)source; } if (supportedVersion.previous() == Object.class) { throw new IllegalVersionException(targetVersion); } return convertToLowerVersion(targetVersion, map(source, supportedVersion.previous(), new DefaultVersionContext())); } }
InterversionConverter { public <T> T convertToLowerVersion(String targetVersion, Object source) { Class<?> sourceType = source.getClass(); SupportedVersion supportedVersion = sourceType.getAnnotation(SupportedVersion.class); if (supportedVersion == null) { throw new IllegalVersionException(targetVersion); } if (targetVersion.equals(supportedVersion.version())) { return (T)source; } if (supportedVersion.previous() == Object.class) { throw new IllegalVersionException(targetVersion); } return convertToLowerVersion(targetVersion, map(source, supportedVersion.previous(), new DefaultVersionContext())); } InterversionConverter(VersionTypeFactory factory, CompatibilityMapper mapper); }
InterversionConverter { public <T> T convertToLowerVersion(String targetVersion, Object source) { Class<?> sourceType = source.getClass(); SupportedVersion supportedVersion = sourceType.getAnnotation(SupportedVersion.class); if (supportedVersion == null) { throw new IllegalVersionException(targetVersion); } if (targetVersion.equals(supportedVersion.version())) { return (T)source; } if (supportedVersion.previous() == Object.class) { throw new IllegalVersionException(targetVersion); } return convertToLowerVersion(targetVersion, map(source, supportedVersion.previous(), 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 convertToLowerVersion(String targetVersion, Object source) { Class<?> sourceType = source.getClass(); SupportedVersion supportedVersion = sourceType.getAnnotation(SupportedVersion.class); if (supportedVersion == null) { throw new IllegalVersionException(targetVersion); } if (targetVersion.equals(supportedVersion.version())) { return (T)source; } if (supportedVersion.previous() == Object.class) { throw new IllegalVersionException(targetVersion); } return convertToLowerVersion(targetVersion, map(source, supportedVersion.previous(), new DefaultVersionContext())); } InterversionConverter(VersionTypeFactory factory, CompatibilityMapper mapper); T convertToLowerVersion(String targetVersion, Object source); T convertToHigherVersion(Class<T> targetType, Object source, String sourceVersion);  }