How to use #SerializedName in Kotlin Multiplatform project? - kotlin

I am using Kotlin multiplatform. I am getting object name in Json response.
I want to map object name with other name. So I found to use #SerializedName.
But it's not working.
It says Unresolved reference: SerializedName.

You can use official kotlin native serialization library for multiplatform. How to add and apply the plugin to your project based on which gradle syntax you are using (either "apply plugin" or "plugin{..}") is described here. After adding dependency you can use #SerialName annotation instead of #SerializedName to override object names.

Related

How can I stop IntelliJ IDEA from turning methods into properties when Kotlinizing a Java file?

In IntelliJ IDEA I can right-click on a Java file and convert it to Kotlin.
It mostly goes well, but this irks me: When the method name starts with is, in Kotlin it comes out as a property instead of a function.
Is there a setting I can change to get Kotlin to convert these methods to functions like all the other methods?
As of Kotlin IDEA plugin 1.4.0, every getter-like method that starts with get or is is always converted into a Kotlin property. This behavior cannot be overridden.
The problem is described in the issue https://youtrack.jetbrains.com/issue/KT-36826, you can vote for it and discuss further on YouTrack.

Firebase Email-Password Authentication using Kotlin in Web Front-End

I am trying to implement Firebase Email-Password Authentication using Kotlin in Web Front-End. But I think we can't do it using Kotlin as Firebase Authentication for Web only supports JS as per the examples I have seen.
So, my first question is: Can we implement it using Kotlin?
If not then, how can we call JS function from Kotlin within a Kotlin file and vice-versa?
Thanks in advance.
JavaScript and Kotlin can easily interoperate. Here I'll provide some excerpts from official documentation as well as links to that documentation.
Calling Kotlin code from JS
To prevent spoiling the global object, Kotlin creates an object that
contains all Kotlin declarations from the current module. So if you
name your module as myModule, all declarations are available to
JavaScript via myModule object. For example:
fun foo() = "Hello"
Can be called from JavaScript like this:
alert(myModule.foo());
Calling JS code from Kotlin
To tell Kotlin that a certain declaration is written in pure
JavaScript, you should mark it with external modifier. When the
compiler sees such a declaration, it assumes that the implementation
for the corresponding class, function or property is provided by the
developer.
I will add here that external function can be provided not necessarily by developer themselves - it can be something that already exist in this environment - like browser API.

Can't find ViewModelProviders class, only ViewModelProvider

I am trying to create lifecycle-aware view models. But I can't find ViewModelProviders class in my Android project, only ViewModelProvider. There seems to be no android.arch.lifecycle.ViewModelProviders package for me to import as well. What's happening
You probably have this dependency included in your project:
implementation "android.arch.lifecycle:viewmodel:$lifecycle_version"
That contains ViewModelProvider (and just 4 other classes), but ViewModelProviders is in a different package:
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
Here are the contents of these packages for reference (as of version 1.1.1):
For the record, you can find this out yourself by looking up the docs for the ViewModelProviders class, where it says up top:
added in version 1.1.0
belongs to Maven artifact android.arch.lifecycle:extensions:1.1.1
Also, just for future reference.
ViewModelProviders class is now deprecated.
According to Android Developers Documentation: ViewModelProviders
This class is deprecated. Use the constructors for ViewModelProvider
directly.

Calling java code that doesn't accept null from kotlin

IDEA Community 2017.1.2, JRE 1.8, Kotlin 1.1.2-2
I have Java methods, located in libGdx that don't have any annotations regarding their nullability, e.g.:
public void render (final RenderableProvider renderableProvider) {
renderableProvider.getRenderables(renderables, renderablesPool);
as we can see, argument can't be null. However, since nothing tells that it's not-null argument, Kotlin will happily pass null in RenderableProvider?. How do I tell Kotlin to check during compile-time that I should be passing RenderableProvider and not RenderableProvider??
I've read about external annotations, however there is no "Specify Custom Kotlin Signature" and if I annotate renderableProvider as #NotNull nothing changes - kotlin still allows null.
I even tried to replace org.jetbrains.annotations.NotNull with javax.annotation.Nonnull in XML manually, but it makes no difference - code compiles and crashes with NPE.
External annotations are no longer supported. You'll either have to fork libgdx and annotate the methods there or live with this issue, unfortunately.
You could wrap it in an extension function and then only use that for rendering:
fun RenderClass.renderSafe(renderProvider: RenderableProvider) =
this.render(renderProvider)
Now you can't pass null.

Warnings while using a plugin and static library in a cocoa project

I have a scenario where I need to use a plugin as well as a static library into my xcode project. The plugin will be dynamically loaded into the system. Now, the static library is also getting used in creation of the plugin.
While executing my project I am getting a warning saying :
Class A is getting referenced from /staticLibraryPath and plugin. One of them will be used.
Please let me know, how to resolve the warning or a better way of implementing the scenario.
The issue is a name class of the two ClassA types found in both plugin and library
I assume you have control over the source of either plugin / library.
.. rename Class A in one instance to make the names not clash -- I don't think there is another way to get rid of the warning/error