小编nav*_*vin的帖子

如何在命令行中使用外部 java 库编译和运行 kotlin 程序

我是第一次尝试 kotlin。

我能够在命令行上在 kotlin 中运行编译 hello world 程序,但我无法编译我想要包含外部 java 库的程序

import com.google.gson.Gson

data class Person(val name: String, val age: Int, val gender: String?)

fun main(args: Array<String>) {
    println("Hello world");
    val gson = Gson()
    val person = Person("navin", 30, null)
    val personJson = gson.toJson(person)
    println(personJson)
}
Run Code Online (Sandbox Code Playgroud)

目录结构

?  kotlin tree
.
??? gson.jar
??? json.jar
??? json.kt

0 directories, 3 files
?  kotlin 
Run Code Online (Sandbox Code Playgroud)

代码编译工作正常,但我无法运行程序

?  kotlin kotlinc -classpath gson.jar json.kt -include-runtime -d json.jar
?  kotlin java -jar json.jar -cp gson.jar                                 
Hello …
Run Code Online (Sandbox Code Playgroud)

java json compiler-errors kotlin

6
推荐指数
1
解决办法
1038
查看次数

将记录中的构造函数转换为 aeson haskell 中的自定义 json 字符串

我想将我的 json 转换为以下格式。并将以下格式转换为我的记录。请检查我在下面编写的代码。

{
    "uid" : "bob",
    "emailid" : "bob@bob.com",
    "email_verified" : "Y" // "Y" for EmailVerified and "N" for EmailNotVerified
}
Run Code Online (Sandbox Code Playgroud)

我有下面的代码,我尝试使用 Haskell 中的 Aeson 库将用户类型与 json 相互转换

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}

import Data.Monoid ((<>))
import GHC.Generics
import Data.Aeson (FromJSON, ToJSON)
import Data.Aeson.Types

data User = User {
    userId :: String,
    userEmail :: String,
    userEmailVerified :: EmailState
  } deriving (Show, Generic)

data EmailState = EmailVerified | EmailNotVerified deriving (Generic, Show)

instance ToJSON User where
    toJSON …
Run Code Online (Sandbox Code Playgroud)

json haskell aeson

4
推荐指数
1
解决办法
428
查看次数

标签 统计

json ×2

aeson ×1

compiler-errors ×1

haskell ×1

java ×1

kotlin ×1