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 ...
随机推荐
- Liferay 6.2 改造系列之二十:修改默认添加用户权限及用户是否拥有个人站点的配置
1.修改默认添加用户权限为User,而非Powers User: 在/portal-master/portal-impl/src/portal.properties文件中有如下配置: # # Inpu ...
- DSP using MATLAB 示例Example2.4
n = [0:10]; x = stepseq(0,0,10) - stepseq(10,0,10); [xe,xo,m] = evenodd(x,n); set(gcf,'Color',[1,1,1 ...
- localhost和127.0.0.1 的区别
- wpf中手风琴控件Accordion编辑模板后控件不正常。
昨天有个网友Accordion控件从sl迁移到wpf时候显示不正常.也是就没有效果. 我也是sl做的比较多,wpf玩的少,Accordion模板里触发器,状态组调了一早上都没达到满意效果, 无奈只有百 ...
- 使用 Velocity 模板引擎快速生成代码
http://www.ibm.com/developerworks/cn/java/j-lo-velocity1/
- 使用Soapui测试webservice接口
本来想自己写一个的,但下面这个资料比较详细(截图和步骤细节),就省事了,具体内容见: http://blog.csdn.net/oracle_microsoft/article/details/568 ...
- 每天一个linux命令--退出<符号
linux出现如下情况: [calendar@test190 logs]$ [calendar@test190 logs]$ [calendar@test190 logs]$ [calendar@te ...
- ural 1071. Nikifor 2
1071. Nikifor 2 Time limit: 1.0 secondMemory limit: 64 MB Nikifor has a number x. He doesn't need it ...
- BZOJ3566 : [SHOI2014]概率充电器
选个根把无根树转化成有根树, 设f[i]表示i不通电的概率 则 答案为对于枚举树根root进行DP后1-f[root]的和 直接算是O(n^2)的,但是n有500000,所以不能过. 对于这样一棵以1 ...
- [Leetcode] Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...