

We found this out the hard way and noticed that our data was not being parsed correctly. The solution is to provide the annotation a target depicting whether the annotation is for the field, the get method, the set method, a method/constructor parameter, return type, etc. Since these fields are in the constructor of the class, there is some ambiguity for the json parser as to whether the parameter is an instance field or a constructor parameter. The parameter = “calories-per-serving”) var calories_per_serving: String? = null will not be parsed from json.But for now, we must allow our Java code to access Kotlin fields as instance fields.

You can then use all of Android Studio’s existing tools with your Kotlin code, including autocompletion, lint checking, refactoring, debugging, and more. But remember, Kotlin automatically adds getters and setters for all fields, which is a feature of Kotlin that makes sense for us when we are 100% Kotlin (i.e. Android Studio fully supports Kotlin, allowing you to add Kotlin files to your existing project and convert Java language code to Kotlin. This was fine when the classes were POJOs. In our Java code we access the instance fields of our network models (such as the one above). This annotation allows the field to be accessed from Java code as an instance field.
