@Test public void convertAddressFromV3ToV1() { AddressV1 address = converter.convertToLowerVersion("v1", new AddressV3("Samplestreet 1", " ", new CityV3("12345", "Samplecity"))); assertThat(address.getStreet().getName(), is("Samplestreet")); assertThat(address.getStreet().getNumber(), is("1")); assertThat(address.getAddressLine1(), is("Samplestreet 1")); assertThat(address.getAddressLine2(), is(" ")); assertThat(address.getCity(), is("12345 Samplecity")); }
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);  }