Why does this json4s code work in the scala repl but fail to compile?
I'm converting a json-like string into json, and the following code works in the scala repl
import org.json4s._
import org.json4s.JsonDSL._
import org.json4s.JsonDSL.WithDouble._
import org.json4s.native.JsonMethods._
val value = "{100:1.50;500:1.00;1000:0.50}"
val data = value.stripPrefix("{").stripSuffix("}").split(";").map(a => {
val b = a.split(":")
(b(0),b(1))
}).toMap
compact(render(data))
But when it is compiled, I'm getting the following error
[error] ... type mismatch;
[error] found : scala.collection.immutable.Map[String,String]
[error] required: org.json4s.JValue
[error] (which expands to) org.json4s.JsonAST.JValue
[error] compact(render(data))
[error] ^
Why is this, and how might I fix it?
I suspect something with the type system that is over my head.
I suspect that the compiler didn't find the implicit due to the ambiguous imports, try to be more selective: the 3rd import seems redundant (the one with Sometimes you can run scalac with -Xlog-implicits to see why implicits are not used. |
Why does this json4s code work in the scala repl but fail to compile?的更多相关文章
- Go 1 Release Notes
Go 1 Release Notes Introduction to Go 1 Changes to the language Append Close Composite literals Goro ...
- Adaptive Code Via C#读书笔记
原书链接: http://www.amazon.com/Adaptive-Code-via-principles-Developer-ebook/dp/B00OCLLYTY/ref=dp_kinw_s ...
- Scala on Visual Studio Code
Download and install Scala Download a scala installation package from here. Then install it. Linux s ...
- How to compile and install Snort from source code on Ubuntu
http://www.tuicool.com/articles/v6j2Ab Snort is by far the most popular open-source network intrusio ...
- Rewrite MSIL Code on the Fly with the .NET Framework Profiling API
http://clrprofiler.codeplex.com/ http://blogs.msdn.com/b/davbr/archive/2012/11/19/clrprofiler-4-5-re ...
- 在 json4s 中自定义CustomSerializer
到目前为止,Scala 环境下至少存在6种 Json 解析的类库,这里面不包括 Java 语言实现的 Json 类库.所有这些库都有一个非常相似的抽象语法树(AST).而 json4s 项目旨在提供一 ...
- 如何在 VS Code 中搭建 Qt 开发环境
前言 VS Code 高大上的界面.强大的智能联想和庞大的插件市场,着实让人对他爱不释手.虽然可以更改 Qt Creator 的主题,但是 Qt Creator 的代码体验实在差劲.下面就来看看如何在 ...
- Akka-CQRS(15)- Http标准安全解决方案:OAuth2+JWT
上期讨论过OAuth2, 是一种身份认证+资源授权使用模式.通过身份认证后发放授权凭证.用户凭授权凭证调用资源.这个凭证就是一种令牌,基本上是一段没什么意义的加密文,或者理解成密钥也可以.服务方通过这 ...
- [转]How to: Create a Custom Principal Identity
本文转自:https://msdn.microsoft.com/en-us/library/aa702720(v=vs.110).aspx The PrincipalPermissionAttribu ...
随机推荐
- javascript 简单加解密
//加密 function MyEncrypt(txt) { var sb = ""; var rand = 0; for (var i=0;i<txt.length;i++ ...
- mathematica练习程序(图像取反)
代码很简单,就四行,我想到可以用mathematica干点什么了. 有人通过mathematica编程研究过视频编解码算法么,挺有意思,可以尝试一下. img=Import["f:/lena ...
- dojo.publish 和 dojo.subscribe
原文链接:http://www.cnblogs.com/didi/archive/2010/06/13/1757894.html //dojo.publish 和 dojo.subscribe :d ...
- CF735D Taxes 哥德巴赫猜想\判定素数 \进一步猜想
http://codeforces.com/problemset/problem/735/D 题意是..一个数n的贡献是它的最大的因子,这个因子不能等于它本身 然后呢..现在我们可以将n拆成任意个数的 ...
- 【jackson 异常】com.fasterxml.jackson.databind.JsonMappingException异常处理
项目中,父层是Gene.java[基因实体] 子层是Corlib.java[文集库实体],一种基因对用多个文集库文章 但是在查询文集库这个实体的时候报错:[com.fasterxml.jackson ...
- jsp遍历、循环
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 1. <% Te ...
- css的重置和原子类的使用
@charset "utf-8";/* Reset Definitions*/body, div, p, a, ul, ol, li, dl, dt, dd, h1, h2, h3 ...
- 使用jQuery要注意的问题
1. $.find()与$.children()的区别 有如下HTML片段: 复制代码代码如下: <div id="div_four"> <input id=&q ...
- Uva 839 Not so Mobile
0.最后输出的yes no的大小写 1.注意 递归边界 一直到没有左右子树 即b1=b2=false的时候 才返回 是否 天平平衡. 2.注意重量是利用引用来传递的 #include <io ...
- zoj 3795 Grouping tarjan缩点 + DGA上的最长路
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Practic ...