https://kotlinlang.org logo
#arrow-meta
Title
# arrow-meta
t

Tim Abil

05/24/2022, 7:21 PM
I'm trying to read moshi's
@Json
property annotation that overrides serialized property names while visiting class properties with
DeclarationDescriptorVisitor
from
declarationChecker{..}
. When
visitPropertyDescriptor
is invoked
descriptor.annotations
is always empty.
Copy code
import com.squareup.moshi.Json

data class Sample(
    val a: Color,
    @Json(name="json_name") <-- not visible from declaration checker
    val b: More,
)
e

ephemient

05/24/2022, 7:32 PM
@Json
doesn't declare applicable targets (therefore all are allowed): https://square.github.io/moshi/1.x/moshi/moshi/com.squareup.moshi/-json/index.html which means it'll be treated as
@param:Json
in this usage by default: https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets
t

Tim Abil

05/24/2022, 7:44 PM
ahh i see, any way to get a reference to those from PropertyDescriptor?
e

ephemient

05/24/2022, 7:45 PM
can you change the code to declare the annotation target explicitly instead?
@property:Json(...) val
t

Tim Abil

05/24/2022, 7:47 PM
hmm i might not have the access to change the class definitions tho
i guess i need to somehow be able to access @Documented string
@raulraja thoughts?
15 Views