@Test(expected = IllegalVersionException.class) public void convertToHigherVersionThrowsExceptionForUnversionedObject() { converter.convertToHigherVersion(LocationV1.class, new LocationV1("12345", "Samplecity"), "v1"); }
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);  }