I’m baffled. And the bytecode viewer is not helpin...
# announcements
c
I’m baffled. And the bytecode viewer is not helping because it throws an exception 🙂
g
My bytecode viewer shows that only constructor param annotated
c
but it’s a
val
, shouldn’t it be present somewhere in the class as well, either as a field or property?
g
@field:Json
annotates field explicitly
c
Yes I know that works, I just don’t want to import this on users, it should be possible to do without
g
Not sure about annotation application strategy by default
What about AnnotationTarget.PROPERTY?
c
The target is a compile time check only, my code wouldn’t compile otherwise
the target is already on
PROPERTY
g
Oh, yeah
do you use Kotlin-reflect?
c
yup
g
I suppose you can get property annotation using kotlin-reflect
c
The code I pasted above wouldn’t compile without it 🙂
g
Okay, got it
e
The target is not check only. It drives where it is applied via some rules.
@udalov
c
I mean a runtime look up cannot fail because the target is wrong since your code wouldn’t even have compiled if the target was wrong
or maybe that problem I’m currently running into is showing I don’t understand how this works 🙂
g
@cedric Works for me with memberProperties instead of declaredMemberProperties
c
Interestingly, I also observed that
I was fixing a bug by doing this replacement and all kinds of regressions appeared
g
Hmm, nope doesn’t work. Probably worked for me only with explicit @property:Json
Works only if I have only AnnotationTarget.PROPERTY
Works if I remove
AnnotationTarget.VALUE_PARAMETER
c
Wow you’re right, removing that target makes
Copy code
val ann = it.findAnnotation<Json>()
work.
Sadly, this means I can no longer do
Copy code
class Child(@Json(ignored = false) foo: String, val bar: String)
which I need
g
Still looks like a bug, or there is some not obvious reason for that
c
That’s my assessment too, hence why I summoned Roman 🙂
g
Maybe make sense to create an issue
c
Yes I will
g
Also, this is not an kotlin-reflect problem. because I don’t see synthetic accessor for property annotations in byte code of class if annotation contains AnnotationTarget.VALUE_PARAMETER
If you want to add comments
g
Yeah, added a comment