Questions tagged [kotlin]

Kotlin stands out as a versatile, statically typed high-level programming language known for its type inference capabilities. Developers often pair Kotlin with other tags related to specific targets (JVM, JavaScript, native, etc.) and libraries/frameworks (Android, Spring, etc.) when seeking advice on those particular areas of development.

The deserialization of 0 and 1 to "Boolean?" failed in Moshi

When attempting to deserialize a JSON field with values of 0, 1, or null into a "Boolean?" data type, the following custom Annotation is used: @Retention(AnnotationRetention.RUNTIME) @JsonQualifier annotation class BooleanType class BooleanAdapter { @ ...

Using Kotlin on the Android platform, learn how to convert a string into a JSON string

Seeking to convert a string into a JSON string using Gson. My desired outcome is to transform "email" into "{"email" : "$email"}" I have the function: fun serializeUserEmail(email: String): String { return &quo ...

Tips for integrating AsyncGenerators with Kotlin/JS

I am currently exploring the use of IPFS with Kotlin/JS, but my issue is not limited to that specific context. The functions ipfs.cat() and ipfs.get() return an AsyncGenerator, and I am uncertain about how to properly iterate over it using Kotlin (I am als ...

Making an HTTP request using Kotlin in an Android application

I attempted to retrieve JSON data or something similar by using URL.readText() from java.net.url in Android Studio, but my application crashes. fun ButtonClick(view:View) { textView.text = URL("https://www.google.com/robots.txt").readText() } ...

Parsing Json into Kotlin Data Class with GSON

I am working with a Java POJO class that looks like this: class Topic { @SerializedName("id") long id; @SerializedName("name") String name; } In addition, I also have a Kotlin data class structured as follows: data class Topic(val id: L ...

Discrepancy in output between Tflite model on Android (ML Vision) and Python platforms

While implementing ML Vision API to generate embeddings from a FaceNet model and comparing cosine distances between the two embeddings, I have noticed significant discrepancies in the output between the Android and Python versions. Surprisingly, the Python ...

Struggling to execute JSON parsing with Klaxon and Anko's doAsync?

I am encountering an issue while attempting to parse a JSON-containing URL upon button click: button.setOnClickListener { doAsync{ val result = URL("http://date.jsontest.com/").readText() val parser ...

Error: Unexpected data type encountered. Expected an array but found a string instead at line 1, column 2

I have tried multiple suggestions from similar questions but none of them have helped. How can I successfully execute this test? @Test fun isJsonCorrectPersonConvert() { val gson = GsonBuilder().create() val json = gson.toJson("[{"Id":2,"Text ...

Utilize Gson in Kotlin to Parse JSON with Nested Objects

I am attempting to transform the JSON below into a list data object: [ { "type": "PHOTO", "id": "pic1", "title": "Photo 1", "dataMap": {} }, { "type": ...

Convert a byte array to Json using Fuel and Result libraries

Looking to retrieve my response body in a JSON Object using Fuel and Result libraries. Here is the callback code I am using: private fun LoginCallback(result: Result<Any, Exception>?) { mAuthTask = null showProgress(false) val (data, er ...

By default, the ItemActiveIndicator is not displayed in the Material 3 Bottom Navigation Bar on Android

Currently, I've added 'com.google.android.material:material:1.5.0' to Build.Gradle <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.andr ...

Kotlin does not interpret 'is' as the beginning of a JSON key

I have encountered a peculiar problem recently. I am working with a data class that is used for parsing Json. Within this data class, there is an attribute: val isExpired: Boolean However, after creating the response, it seems that instead of using isE ...

What is the process of extracting "error" or "success" from JSON data using Kotlin?

While working on developing a web android app using Kotlin, I have been learning something new every day. However, there is one error that I have not been able to find a solution for. I am using OkHTTP3 and Klaxon for handling JSON data. My main requiremen ...

Difference between an optional field and a null value in kotlinx.serialization

Is there a way to differentiate between handling {data: null} and {} when parsing JSON using kotlinx.serialization? @Serializable class MyClass(val data: String?) ...

How can I store multiple objects of the same type within another object using serialization?

I'm trying to convert the JSON data below into a Kotlin data class for easier handling. I need a list of players, each represented as an object, but I'm struggling with serialization when dealing with objects of the same type. "Players" ...

Using Kotlin to convert a map collection to a JSON array using Jackson

Recently started learning Kotlin, I'm attempting to configure a web server using the kotlin spring webserver template I need assistance with converting a kotlin collection into an array of JSON objects The endpoint is called test @PostMapping(value = [ ...

Using Kotlin to work with JSON strings that contain line breaks and variables

In need of help adding linebreakers to a JSON string for improved readability. val myString = "some string" val myObjectJson = ` { "example1": "value", "example2": $myString }` This will allow me to utilize ...

Converting JSON data into Kotlin objects: a step-by-step guide

Having a sample of an existing JSON, my challenge lies in converting it to Kotlin. As I am relatively new to Kotlin and have been studying various tutorials, I have yet to come across examples as complex as this. Here is the JSON: { "mobile": { "id": ...

What steps are involved in including the Gradle Kotlin dependency for the compile group 'org.seleniumhq.selenium'?

Can anyone provide the syntax for adding Selenium as a dependency using the Gradle Kotlin DSL? Error: thufir@dur:~/NetBeansProjects/HelloKotlinWorld$ thufir@dur:~/NetBeansProjects/HelloKotlinWorld$ gradle clean > Configure project : e: /home/thufir/ ...

The spacing between elements is too wide, preventing me from adjusting the image upwards

Currently, I am working on designing a screen layout for my app, and no matter what I do, I am unable to successfully align all the elements as intended. Can anyone guide me on where I might be going wrong? Column( modifier = Modifier, verticalArra ...

Add a Maven library dependency to the npm package.json file

When building a Kotlin multiplatform library using Gradle, I utilize the org.jetbrains.kotlin.multiplatform plugin. The library is built for mobile, Java, and JavaScript platforms. The problem arises when this plugin only publishes the output into a Maven ...

Learn the process of converting C# code to Kotlin with the incorporation of a Json library

Hello, I am new to Kotlin and apologize for my poor English. I am trying to convert the code snippet below to Kotlin. However, I am having trouble finding the equivalent of [JsonExtensiondata] in Kotlin. public class ProofAttribute { [JsonProperty(&q ...

Working with JSON Strings using moshi and retrofit2

The API I am currently utilizing responds with a JSON object nested inside a list structure: [ { "name": "Seattle", "lat": 47.6038321, "lon": -122.3300624, "country": &qu ...

Converting JSON Responses in Android: A Guide

After creating my JSON response model class, here is how it looks: data class MyModelClass( val one: String, val two: String, val three: String, val four: Int, val tempCurrentCharge: List<CurrentCharge>, ...

Loading Google Books JSON data into a ListView

Currently, I am utilizing the Google Books API to search for books. However, I am encountering an issue when trying to populate my ListView with the searched books as it is throwing an error specifically in the onPostExecute method, but I am unable to iden ...

Utilizing Selenium, Kotlin, and PageFactory to instantiate a collection of web elements

I've been experimenting with PageFactory and Selenium, but I'm encountering difficulties when dealing with lists of elements. Here's the code snippet causing me trouble: @FindBy(css = "timeline-instances [data-e2e-selector=inst]") lateinit var t ...

The React Native app encountered an error while trying to compile Kotlin code for the expo-splash-screen task

Just a while ago, everything was running smoothly with the React Native app on Android. It even successfully built on Azure DevOps. But then, when I tried to run the app again, this unexpected error occurred: * What went wrong: Execution failed for task & ...

The issue I am facing is that when using Retrofit to make a POST

After spending countless hours working on this, I've hit a roadblock. As someone new to retrofit, my goal is to create a basic post request with jsonObject, but I keep running into the following error: java.lang.illegalStateException: Expected BEGIN_O ...

"Android Webview's evaluateJavascript function is not returning the expected value

I am attempting to retrieve the username from a webview, but it is returning a null object. webView.settings.javaScriptEnabled = true webView.evaluateJavascript( "(function() { return document.getElementsByClassName('lgn-loginname') })() ...

Decoding with Gson: Say No to Wrapper Classes

Working on deserializing the JSON data provided using Gson in Kotlin. { "things": [ { "name": "Thing1" }, { "name": "Thing2" } } } Currently, there are two classes involved in deserialization; ThingWrapper - Contains a p ...

I'm curious if there is a method to extract and retrieve color text information from JSON using Kotlin

I'm currently working on parsing and extracting data from JSON. However, I would like the respective color to be displayed instead of just the color name. For example: { "id": 1, "name": rose, "color ...

Develop a unique Kotlin/JS WebComponent featuring custom content

I am trying to create a custom tag using Kotlin that includes default content. While the example I found works well, I am having trouble adding default content (such as an input element) inside the custom tag. After attempting various approaches, I have o ...

Creating a wrapper from index.d.ts in Kotlin JS

I am currently exploring the possibility of utilizing Kotlin JS for an express application. It has come to my attention that there is no full, current wrapper available for express, however the package includes type definitions in its index.d.ts file. I' ...

Selecting Map Types on Android Google Maps through the Floating Action Button (FAB) menu

Is there a way to create a visually appealing menu for changing the map type, similar to the one on Google Maps? This menu should appear when clicking the layers FAB. I'm unsure if it's a custom FAB menu or if it animates and opens a fragment. https://i.s ...

What is the best source for JSON serialization when using Ktor?

Having some trouble sending requests with Kotlin through Ktor. Android Studio doesn't seem to recognize the JSON serialization imports I'm trying to use. Here are the dependencies in my build.gradle.kts (:app): implementation("io.ktor:ktor- ...

Is there a way to smoothly transition to the starting index of a LazyColumn when utilizing SnapFlingBehavior in Jetpack Compose?

Hey there, I've got a fascinating question to discuss about snapping in Compose development. With the introduction of snapping as a 1st class API for LazyColumn, replacing the Snapper library, a new query has emerged. How can one initialize the LazyCo ...

A beginner's guide to implementing dot navigation within the Jackson JsonNode

Take a look at this code snippet: val parsedData = ObjectMapper().readTree(vcap) parsedData.get("spaces")?.firstOrNull()?.get("block1")?.asText() I'm interested in improving the readability of this code by using dot notation for navigation. Here's an ex ...