wujunbin
wujunbin

Reputation: 361

Runtime annotations annotated on a filed in kotlin class are not generated correctly

Kotlin compiler remove the Java runtime annotation annotated on a field.The annotation is shown below.

@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@com.fasterxml.jackson.annotation.JacksonAnnotation
public @interface JsonDeserialize

I declared it on a field, as seen below.

@JsonSerialize(using = IDEncryptJsonSerializer::class)
@JsonDeserialize(using = IDDecryptJsonDeserializer::class)
@Column(name = "sku_id", nullable = false)
open var skuId: Long = 0L

The annotation doesn't work. Then, I take a fist look at the class file, as seen below.

@field:javax.persistence.Column public open var skuId: kotlin.Long

The JsonDeserialize and JsonSerialize annotation are dismiss. The two annotations are work well in Java. My kotlin version is 1.1.4. How can I fix the problem?

Upvotes: 3

Views: 1131

Answers (1)

wujunbin
wujunbin

Reputation: 361

Finally, I found the reason that result in the phenomenon. If I declare a variable in class constructor, some of annotations annotate on that variable may cannot be compiled correctly. Some of annotations may be lost because of kotlin compiler bug. Then, I move the variable in the class body. Everything work well.

Upvotes: 3

Related Questions