问题标签 [jerkson]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
3291 浏览

json - JsonProperty 注释不适用于 Scala 中的 Json 解析 (Jackson/Jerkson)

我需要解析以下 json 字符串:

{“类型”:1}

我正在使用的案例类如下所示:

然而,这让 Scala 感到困惑,因为 'type' 是一个关键字。因此,我尝试使用来自 Jacson/Jerkson 的 @JsonProperty 注释,如下所示:

但是,Json 解析器仍然拒绝在 json 中查找 'type' 字符串而不是 'myType'。以下示例代码说明了问题:

我收到以下错误:

PS:如上所示,我正在使用 jerkson/jackson,但如果这样可以让生活更轻松,我不介意切换到其他一些 json 解析库。

0 投票
2 回答
1486 浏览

json - Parsing JSON with multiple tuples to List in scala
[
{"fname":"Foo","lname":"Pacman"},
{"fname":"Bar","lname":"Mario"},
{"fname":"Poo","lname":"Wario"}
]

Well I have JSON string in this format, Now what

Well I have JSON string in this format, Now what I need is to convert each tuples -> {"fname":"Foo","lname":"Pacman"}

To a Person object, for e.g. lets assume I have a case class

case class Person(fname:String,lname:String)

Now how am I to get, List<person>

If I had a JSON containing data for single tuple, then I could,

val o:Person = parse[Person](jsonString)// I am actually using Jerkson Lib

But since there are more than one tuples, how am i to parse them individually and create objects and create a list.


Replace standard javascript confirm with Twitter Bootstrap's modal - who triggered it?

I'm trying to replace the standard javascript confirm with a twitter bootstrap modal window. Everything is almost working (the modal is shown with its confirm text), but I'm stuck trying to catch the caller href, which I need to bind the "ok" button.

Here's my code (almost working example: http://jsfiddle.net/k5uDw/):

Any hint? Please note that I would like this to be a drop-in replacement for standard javascript confirm, so modifying the way the confirm itself is called it is not a possibility (if this plugin is active -> then the modal is shown, if this plugin is not active -> then the standard confirm is fired).

0 投票
1 回答
232 浏览

scala - 为什么我不能使用自定义 Scala 类型 (Jerkson) 解析这个 JSON 字符串?

我有以下代码,用于使用Jerkson(Jackson 的 Scala 包装器)解析以下 JSON 字符串:

代码val vertex = Json.parse[Ranked[UserVertex]](rawString)

杰森"originalPos":"515693049","rankScore":1.2409032357406248E8,"ranked":{"userId":"101010110","userName":"John","channel":"thirtyfive"}}

下面的 JSON 由这个 Scala 类表示:

T 是一个UserVertex类,上面有以下字段(userId、userName、channel)。当我尝试解析 JSON 字符串时,出现以下错误:

看起来 ClassLoader 找不到该类,但它肯定已加载。知道这是什么根本原因吗?我这里有某种多类加载器问题吗?谢谢!

0 投票
2 回答
238 浏览

json - 具有自动序列化的 Scala JSON 库(通过自省)

我正在为 Scala 寻找一个好的 JSON 库,它可以将任意对象图序列化为 JSON,而无需我编写映射代码。

Java 的 Jackson 做到了这一点,但它不是 Scala 原生的,我在反序列化嵌套泛型(我将其归因于 Java 类型系统)时遇到了一些麻烦。Jerkson 是 Jackson 的 Scala 包装器,但它已经被废弃了几年。

你有什么建议吗?

0 投票
0 回答
61 浏览

scala - 如何创建通用方法来解析嵌套的 json?

我找到了我的微服务路线。我有通用 API 可以与任何微服务通信并使用 jerkson JSON 库。

现在我有一个单例,其中包含访问另一个服务的路由的方法列表。

我有两个案例课,

case class QualifyingProductSummary(upcCode: String, description: Option[String], purchase: Option[Double]) case class ProductPurchaseResponse(qualifyingProducts:List[QualifyingProducts], count: Int)

json:

当我使用任何一个时,要从 ApiResult 中获取数据,

由于QualifyingProducts,它无法在ProductPurchaseResponse中解析它。那么如何使用同一个库来实现呢?我希望通用方法也对其他嵌套的 JSON 执行相同的操作。

提前致谢。