Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Unable to find getter for List<Map<String, String>> #182

Open
MRezaNasirloo opened this issue Aug 29, 2018 · 1 comment
Open

Unable to find getter for List<Map<String, String>> #182

MRezaNasirloo opened this issue Aug 29, 2018 · 1 comment
Labels

Comments

@MRezaNasirloo
Copy link

Issue Summary

Stag fails to find the getter for a list of maps,

Reproduction Steps

@UseStag
@Generated("com.robohorse.robopojogenerator")
data class RequestBodyTransaction(
        @field:SerializedName("restrictions")
        var listOfMaps: List<Map<String, String>> = emptyList()
)

Expected Behavior

To work and parse a list of maps

Actual Behavior

A Compile error as below

RequestBodyTransaction.java:16: error: Unable to find getter for variable: restrictions
    private java.util.List<? extends java.util.Map<java.lang.String, java.lang.String>> restrictions;
                                                                                        ^
@anthonycr anthonycr added the bug label Sep 11, 2018
@anthonycr
Copy link
Contributor

anthonycr commented Sep 11, 2018

This is caused by Kotlin's use of type variance and Stag's only partial support for kotlin. The generated bytecodecode resolves to:

private List<? extends Map<String, String> restrictions;

public List<Map<String, String> getRestrictions() { ... }

public void setRestrictions(List<? extends Map<String, String> restrictions) { ... }

Exact equality between types is expected using Types.isSameAs within Stag. This does not return true for the two types List<? extends T> and List`, and therefore causes a build error. The long-term solution would be to build support for type variance into the processor, but short-term this isn't feasible as it will be quite difficult.

The workaround for this is to utilize the @JvmSuppressWildcards annotation. You can apply it to the type parameter of any generic collection that you are getting the error for. For instance, the above failing example you provided will compile when changed to this:

@UseStag
@Generated("com.robohorse.robopojogenerator")
data class RequestBodyTransaction(
        @field:SerializedName("restrictions")
        var listOfMaps: List<@JvmSuppressWildcards Map<String, String>> = emptyList()
)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants