Lucas
10/13/2022, 1:11 AMVitor Hugo Schwaab
10/13/2022, 6:26 AMBig Chungus
10/13/2022, 8:31 AMVitor Hugo Schwaab
10/13/2022, 8:34 AM// ## Common source
@JvmJsonProperty(required = false, access = JsonPropertyAccess.WRITE_ONLY)
Big Chungus
10/13/2022, 8:35 AMVitor Hugo Schwaab
10/13/2022, 8:49 AM// Some External JVM Library that it's being used in the JVM
annotation class LibAnnotation(val enum: LibEnum)
enum class LibEnum { A, B }
Now, in the common code, we need to call the LibAnnotation
constructor with the LibEnum
parameter. Can't do that directly, so expect/actual needed.
// Common Code
/**
* An annotation that will only affect JVM targets
*/
expect annotation class JvmLibAnnotation(val enum: ???)
// This way it can be used like so:
@JvmLibAnnotation(enum = ???)
// JVM Code
actual typealias JvmLibAnnotation = JsonProperty
What to put in the ???
Big Chungus
10/13/2022, 9:01 AMVitor Hugo Schwaab
10/13/2022, 9:22 AM// Common Code
@JvmLibAnnotation(enum = LibEnum.A) // A is not defined in common, only in JVM
Big Chungus
10/13/2022, 9:32 AMVitor Hugo Schwaab
10/13/2022, 9:34 AMBig Chungus
10/13/2022, 9:36 AMRobert Jaros
10/13/2022, 10:41 AMLucas
10/13/2022, 12:00 PMactual typealias JvmJsonProperty = JsonProperty
had errors, but anottating it with @OptionalExpectation and removing the arguments worked. At least it doesnt give me an error, still have to test it.
Thanks a lot @Vitor Hugo Schwaab and @Big ChungusVitor Hugo Schwaab
10/13/2022, 12:26 PMLucas
10/13/2022, 1:01 PMVitor Hugo Schwaab
10/13/2022, 1:03 PMRobert Jaros
10/13/2022, 1:08 PM@OptIn(ExperimentalMultiplatform::class)
@OptionalExpectation
expect annotation class JsonProperty(
val value: String,
val namespace: String,
val required: Boolean,
val index: Int,
val defaultValue: String,
val access: Access
)
expect enum class Access {
AUTO, READ_ONLY, WRITE_ONLY, READ_WRITE;
}
// annotation usage (default values not working)
@JsonProperty(value = "", namespace = "", required = true, index = -1, defaultValue = "", access = Access.AUTO)
JVM code:
actual typealias Access = JsonProperty.Access
actual typealias JsonProperty = com.fasterxml.jackson.annotation.JsonProperty
Lucas
10/13/2022, 1:09 PMAshutosh Verma
02/18/2023, 2:10 PMLucas
02/18/2023, 4:00 PM