This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Complicated type error with org.json.simple.JSONObject:put

7 replies
Sébastien Pierre
Joined: 2009-12-09,
User offline. Last seen 42 years 45 weeks ago.
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.
Mohamed Bana 2
Joined: 2009-10-21,
User offline. Last seen 42 years 45 weeks ago.
Re: Complicated type error with org.json.simple.JSONObject:put
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 [dot] pierre [at] gmail [dot] 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.

Sébastien Pierre
Joined: 2009-12-09,
User offline. Last seen 42 years 45 weeks ago.
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 [at] bana [dot] org [dot] 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 [dot] pierre [at] gmail [dot] 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.


David Hall 4
Joined: 2009-08-21,
User offline. Last seen 42 years 45 weeks ago.
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.

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
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{

Christopher Schmidt
Joined: 2009-11-09,
User offline. Last seen 42 years 45 weeks ago.
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{

Sébastien Pierre
Joined: 2009-12-09,
User offline. Last seen 42 years 45 weeks ago.
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 [dot] Schmidt [at] eads [dot] 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 [at] improving [dot] 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{



bmaso
Joined: 2009-10-04,
User offline. Last seen 2 years 41 weeks ago.
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 [at] blumenfeld-maso [dot] com
twitter: @bmaso
skype: brian.maso
LinkedIn: http://www.linkedin.com/in/brianmaso

2009/12/15 Christopher Schmidt <Christopher [dot] Schmidt [at] eads [dot] 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 [at] improving [dot] 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{



Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland