https://kotlinlang.org logo
Title
c

cedric

03/13/2018, 5:45 AM
I’m baffled. And the bytecode viewer is not helping because it throws an exception 🙂
g

gildor

03/13/2018, 5:46 AM
My bytecode viewer shows that only constructor param annotated
c

cedric

03/13/2018, 5:48 AM
but it’s a
val
, shouldn’t it be present somewhere in the class as well, either as a field or property?
g

gildor

03/13/2018, 5:49 AM
@field:Json
annotates field explicitly
c

cedric

03/13/2018, 5:50 AM
Yes I know that works, I just don’t want to import this on users, it should be possible to do without
g

gildor

03/13/2018, 5:50 AM
Not sure about annotation application strategy by default
What about AnnotationTarget.PROPERTY?
c

cedric

03/13/2018, 5:53 AM
The target is a compile time check only, my code wouldn’t compile otherwise
the target is already on
PROPERTY
g

gildor

03/13/2018, 5:54 AM
Oh, yeah
do you use Kotlin-reflect?
c

cedric

03/13/2018, 5:54 AM
yup
g

gildor

03/13/2018, 5:54 AM
I suppose you can get property annotation using kotlin-reflect
c

cedric

03/13/2018, 5:55 AM
The code I pasted above wouldn’t compile without it 🙂
g

gildor

03/13/2018, 5:55 AM
Okay, got it
e

elizarov

03/13/2018, 6:13 AM
The target is not check only. It drives where it is applied via some rules.
@udalov
c

cedric

03/13/2018, 6:14 AM
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

gildor

03/13/2018, 6:19 AM
@cedric Works for me with memberProperties instead of declaredMemberProperties
c

cedric

03/13/2018, 6:20 AM
Interestingly, I also observed that
I was fixing a bug by doing this replacement and all kinds of regressions appeared
g

gildor

03/13/2018, 6:25 AM
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

cedric

03/13/2018, 6:34 AM
Wow you’re right, removing that target makes
val ann = it.findAnnotation<Json>()
work.
Sadly, this means I can no longer do
class Child(@Json(ignored = false) foo: String, val bar: String)
which I need
g

gildor

03/13/2018, 6:39 AM
Still looks like a bug, or there is some not obvious reason for that
c

cedric

03/13/2018, 7:02 AM
That’s my assessment too, hence why I summoned Roman 🙂
g

gildor

03/13/2018, 7:07 AM
Maybe make sense to create an issue
c

cedric

03/13/2018, 7:07 AM
Yes I will
g

gildor

03/13/2018, 7:09 AM
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

gildor

03/13/2018, 7:15 AM
Yeah, added a comment