- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Complicated type error with org.json.simple.JSONObject:put
Wed, 2009-12-09, 21:15
Hello there !
I am a Scala newbie with a background in Java and Python, and am getting the following errors while using the org.json.simple library from within Scala:
Can anybody shed some light on this ?
-- Sébastien
PS: To try this example, simply get this jar http://json-simple.googlecode.com/files/json_simple-1.1.jar and add it to your $CLASSPATH, then run it in scala.
I am a Scala newbie with a background in Java and Python, and am getting the following errors while using the org.json.simple library from within Scala:
scala> val o = new org.json.simple.JSONObject() o: org.json.simple.JSONObject = {}
scala> o.put("a",1) <console>:6: error: overloaded method value put with alternatives (K,V)V <and> ((K with K,_2)_2) forSome { type _2 >: V with V } cannot be applied to (java.lang.String,Int) o.put("a",1) ^
Can anybody shed some light on this ?
-- Sébastien
PS: To try this example, simply get this jar http://json-simple.googlecode.com/files/json_simple-1.1.jar and add it to your $CLASSPATH, then run it in scala.
Mon, 2009-12-14, 23:57
#2
Re: Complicated type error with org.json.simple.JSONObject:put
Hi Mohamed,
It looks like I'm going to try a Scala JSON library, but I'm a bit concerned about encountering such cryptic type errors by simply using a well-known Java library. Do you have any idea what the type error means ?
overloaded method value put with alternatives (K,V)V <and> ((K with K,_2)_2) forSome { type _2 >: V with V } cannot be applied to (java.lang.String,Int)
-- Sébastien
Le 12 décembre 2009 16:41, Mohamed Bana <mohamed@bana.org.uk> a écrit :
It looks like I'm going to try a Scala JSON library, but I'm a bit concerned about encountering such cryptic type errors by simply using a well-known Java library. Do you have any idea what the type error means ?
overloaded method value put with alternatives (K,V)V <and> ((K with K,_2)_2) forSome { type _2 >: V with V } cannot be applied to (java.lang.String,Int)
-- Sébastien
Le 12 décembre 2009 16:41, Mohamed Bana <mohamed@bana.org.uk> a écrit :
Did you get an answer?
I don't think I'd use that. I tried using a scala.map; JSONValue.toJSONString(Map(...)) and it didn't like it.
Have you tried
http://github.com/dpp/liftweb/tree/master/lift-base/lift-json/ http://github.com/jjmmcc/scala0.json/
2009/12/9 Sébastien Pierre <sebastien.pierre@gmail.com>
Hello there !
I am a Scala newbie with a background in Java and Python, and am getting the following errors while using the org.json.simple library from within Scala:scala> val o = new org.json.simple.JSONObject() o: org.json.simple.JSONObject = {}
scala> o.put("a",1) <console>:6: error: overloaded method value put with alternatives (K,V)V <and> ((K with K,_2)_2) forSome { type _2 >: V with V } cannot be applied to (java.lang.String,Int) o.put("a",1) ^
Can anybody shed some light on this ?
-- Sébastien
PS: To try this example, simply get this jar http://json-simple.googlecode.com/files/json_simple-1.1.jar and add it to your $CLASSPATH, then run it in scala.
Tue, 2009-12-15, 00:27
#3
Re: Complicated type error with org.json.simple.JSONObject:put
Taking a peak at the source code
(http://code.google.com/p/json-simple/source/browse/trunk/src/org/json/si...),
it looks like the author decided to use raw types when inheriting from
HashMap, instead of . I'm not really in a place to test
out the hypothesis, but I bet that that's the problem.
It's still present in 2.8.0.Beta1-RC2, so it might be worth filing a
bug over. Alternatively, you could ask the simple json people to
change it to (or ). That kind of
implementation inheritance is really ugly anyway.
Tue, 2009-12-15, 00:47
#4
Re: Complicated type error with org.json.simple.JSONObject:put
On Mon, Dec 14, 2009 at 05:56:03PM -0500, Sébastien Pierre wrote:
> It looks like I'm going to try a Scala JSON library, but I'm a bit
> concerned about encountering such cryptic type errors by simply using
> a well-known Java library. Do you have any idea what the type error
> means ?
It means the library is all written with raw types, and as if that
weren't enough, JSONObject extends HashMap raw:
public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAware
I don't even know how to work around that without modifying the source.
If you recompile it like this and build with source/target 1.5 it works.
public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAware{
Tue, 2009-12-15, 11:27
#5
Re: Complicated type error with org.json.simple.JSONObject:put
Or use codehaus jettison JSON implementation, it works fine with Scala.
Regards CS
Am 15.12.09 00:28 schrieb "Paul Phillips" unter :
> On Mon, Dec 14, 2009 at 05:56:03PM -0500, Sébastien Pierre wrote:
>> It looks like I'm going to try a Scala JSON library, but I'm a bit
>> concerned about encountering such cryptic type errors by simply using
>> a well-known Java library. Do you have any idea what the type error
>> means ?
>
> It means the library is all written with raw types, and as if that
> weren't enough, JSONObject extends HashMap raw:
>
> public class JSONObject extends HashMap implements Map, JSONAware,
> JSONStreamAware
>
> I don't even know how to work around that without modifying the source.
> If you recompile it like this and build with source/target 1.5 it works.
>
> public class JSONObject extends HashMap implements Map Object>, JSONAware, JSONStreamAware{
Tue, 2009-12-15, 14:27
#6
Re: Complicated type error with org.json.simple.JSONObject:put
Thanks everyone for the answer,
I've filed a bug to json-simple, and will be filing a bug to scala as soon as the registration is processed.
-- Sébastien
I'll file a bug to Scala and
Le 15 décembre 2009 05:29, Christopher Schmidt <Christopher.Schmidt@eads.com> a écrit :
I've filed a bug to json-simple, and will be filing a bug to scala as soon as the registration is processed.
-- Sébastien
I'll file a bug to Scala and
Le 15 décembre 2009 05:29, Christopher Schmidt <Christopher.Schmidt@eads.com> a écrit :
Or use codehaus jettison JSON implementation, it works fine with Scala.
Regards CS
Am 15.12.09 00:28 schrieb "Paul Phillips" unter <paulp@improving.org>:
> On Mon, Dec 14, 2009 at 05:56:03PM -0500, Sébastien Pierre wrote:
>> It looks like I'm going to try a Scala JSON library, but I'm a bit
>> concerned about encountering such cryptic type errors by simply using
>> a well-known Java library. Do you have any idea what the type error
>> means ?
>
> It means the library is all written with raw types, and as if that
> weren't enough, JSONObject extends HashMap raw:
>
> public class JSONObject extends HashMap implements Map, JSONAware,
> JSONStreamAware
>
> I don't even know how to work around that without modifying the source.
> If you recompile it like this and build with source/target 1.5 it works.
>
> public class JSONObject extends HashMap<Object, Object> implements Map<Object,
> Object>, JSONAware, JSONStreamAware{
Tue, 2009-12-15, 16:47
#7
Re: Complicated type error with org.json.simple.JSONObject:put
And, apopros of using jettison, you can use scala.xml.XML.load(org.xml.sax.InputSource) to convert a SAX-encoded doc to a scala.xml.Elem.
Anyone know of a easy way to convert StAX-encoded to scala Elem?
Best regards,
Brian Maso
(949) 395-8551
brian@blumenfeld-maso.com
twitter: @bmaso
skype: brian.maso
LinkedIn: http://www.linkedin.com/in/brianmaso
2009/12/15 Christopher Schmidt <Christopher.Schmidt@eads.com>
Anyone know of a easy way to convert StAX-encoded to scala Elem?
Best regards,
Brian Maso
(949) 395-8551
brian@blumenfeld-maso.com
twitter: @bmaso
skype: brian.maso
LinkedIn: http://www.linkedin.com/in/brianmaso
2009/12/15 Christopher Schmidt <Christopher.Schmidt@eads.com>
Or use codehaus jettison JSON implementation, it works fine with Scala.
Regards CS
Am 15.12.09 00:28 schrieb "Paul Phillips" unter <paulp@improving.org>:
> On Mon, Dec 14, 2009 at 05:56:03PM -0500, Sébastien Pierre wrote:
>> It looks like I'm going to try a Scala JSON library, but I'm a bit
>> concerned about encountering such cryptic type errors by simply using
>> a well-known Java library. Do you have any idea what the type error
>> means ?
>
> It means the library is all written with raw types, and as if that
> weren't enough, JSONObject extends HashMap raw:
>
> public class JSONObject extends HashMap implements Map, JSONAware,
> JSONStreamAware
>
> I don't even know how to work around that without modifying the source.
> If you recompile it like this and build with source/target 1.5 it works.
>
> public class JSONObject extends HashMap<Object, Object> implements Map<Object,
> Object>, JSONAware, JSONStreamAware{
I don't think I'd use that. I tried using a scala.map; JSONValue.toJSONString(Map(...)) and it didn't like it.
Have you tried
http://github.com/dpp/liftweb/tree/master/lift-base/lift-json/ http://github.com/jjmmcc/scala0.json/
2009/12/9 Sébastien Pierre <sebastien.pierre@gmail.com>