forked from svt/encore
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix profile deserialization in native compiled image
Signed-off-by: Gustav Grusell <[email protected]>
- Loading branch information
Showing
5 changed files
with
105 additions
and
15 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
encore-common/src/main/kotlin/se/svt/oss/encore/ReflectionConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package se.svt.oss.encore | ||
|
||
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding | ||
import org.springframework.context.annotation.Configuration | ||
import se.svt.oss.encore.model.profile.AudioEncode | ||
import se.svt.oss.encore.model.profile.AudioEncoder | ||
import se.svt.oss.encore.model.profile.GenericVideoEncode | ||
import se.svt.oss.encore.model.profile.OutputProducer | ||
import se.svt.oss.encore.model.profile.Profile | ||
import se.svt.oss.encore.model.profile.SimpleAudioEncode | ||
import se.svt.oss.encore.model.profile.ThumbnailEncode | ||
import se.svt.oss.encore.model.profile.ThumbnailMapEncode | ||
import se.svt.oss.encore.model.profile.VideoEncode | ||
import se.svt.oss.encore.model.profile.X264Encode | ||
import se.svt.oss.encore.model.profile.X265Encode | ||
import se.svt.oss.encore.model.profile.X26XEncode | ||
|
||
@RegisterReflectionForBinding( | ||
AudioEncode::class, | ||
AudioEncoder::class, | ||
GenericVideoEncode::class, | ||
OutputProducer::class, | ||
Profile::class, | ||
SimpleAudioEncode::class, | ||
ThumbnailEncode::class, | ||
ThumbnailMapEncode::class, | ||
VideoEncode::class, | ||
X26XEncode::class, | ||
X264Encode::class, | ||
X265Encode::class | ||
) | ||
@Configuration | ||
class ReflectionConfiguration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
encore-common/src/test/kotlin/se/svt/oss/encore/model/profile/ProfileJsonTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package se.svt.oss.encore.model.profile | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import org.junit.jupiter.api.Test | ||
import se.svt.oss.encore.model.profile.ProfileAssert.assertThat | ||
|
||
class ProfileJsonTest { | ||
|
||
private val yamlMapper = YAMLMapper().findAndRegisterModules().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | ||
private val objectMapper = ObjectMapper().findAndRegisterModules().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | ||
|
||
@Test | ||
fun testSerializeProgramToJson() { | ||
serializeDeserializeJson(readProfile("/profile/program.yml")) | ||
} | ||
|
||
@Test | ||
fun testSerializeProgramX265ToJson() { | ||
serializeDeserializeJson(readProfile("/profile/program-x265.yml")) | ||
} | ||
|
||
@Test | ||
fun testSerializeProgramToYaml() { | ||
serializeDeserializeYaml(readProfile("/profile/program.yml")) | ||
} | ||
|
||
@Test | ||
fun testSerializeProgramX265ToYaml() { | ||
serializeDeserializeYaml(readProfile("/profile/program-x265.yml")) | ||
} | ||
|
||
private fun serializeDeserializeJson(profile: Profile) { | ||
val pretty = ObjectMapper().findAndRegisterModules().writerWithDefaultPrettyPrinter() | ||
println(pretty.writeValueAsString(profile)) | ||
val serialized = objectMapper.writeValueAsString(profile) | ||
val deserialized: Profile = objectMapper.readValue(serialized, Profile::class.java) | ||
assertThat(deserialized) | ||
.isEqualTo(profile) | ||
} | ||
|
||
private fun serializeDeserializeYaml(profile: Profile) { | ||
val pretty = YAMLMapper().findAndRegisterModules().writerWithDefaultPrettyPrinter() | ||
println(pretty.writeValueAsString(profile)) | ||
val serialized = yamlMapper.writeValueAsString(profile) | ||
val deserialized: Profile = yamlMapper.readValue(serialized, Profile::class.java) | ||
assertThat(deserialized) | ||
.isEqualTo(profile) | ||
} | ||
|
||
private fun readProfile(path: String): Profile = | ||
ProfileJsonTest::class.java.getResourceAsStream(path).use { | ||
yamlMapper.readValue(it) | ||
} | ||
} |