42

I need some simple JSON parsing in my application and the Douglas Crockford library seems exactly what I need.

However, I seem to be running into a problem. I'm getting the following error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/json/JSONObject : Unsupported major.minor version 52.0

I Googled around a bit and I get the impression that this is due to some version incompatibility. I've tried changing Java versions but it doesn't seem to help. I'm using Java 7 and Java 7 features in my program and ultimately I want to use Java 7.

How can I resolve this issue?

PS: I looked at Jackson and GSON and definitely don't want to use either so please don't suggest as an alternative.

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
Luke
  • 20,878
  • 35
  • 119
  • 178
  • 4
    `Unsupported major.minor version 52.0` indicates that that library was compiled with Java 8. Can you get the [source](https://github.com/douglascrockford/JSON-java) and recompile the library for your version? –  Dec 08 '14 at 06:44
  • 4
    that's do-able, but kinda' goes around the point of using a package manager... – chaqke Feb 18 '15 at 00:19

2 Answers2

67

Have you tried using an older version of the package?

Try: http://mvnrepository.com/artifact/org.json/json/20140107

Luke
  • 20,878
  • 35
  • 119
  • 178
David ten Hove
  • 2,748
  • 18
  • 33
  • 3
    Just trying this and seems to work. It's a shame, even though I can't tell for sure, I don't think the library "needs" Java 8, so compiling it for Java 8 seems quite unnecessary. – Luke Dec 08 '14 at 08:31
  • @Luke Well as MichaelT said, if you really want to use the newest version you can compile the sources yourself – David ten Hove Dec 08 '14 at 08:35
  • 2
    Yep. Understood, but I prefer to manage dependencies through a dependency manager (such as Maven). – Luke Dec 08 '14 at 22:45
  • 1
    Verified that version 20140107 works using Maven 3.1.1 / Tycho 0.22.0 / JDK 7_17. Only question really is the MIT/DoNoEvil license - http://en.wikipedia.org/wiki/Douglas_Crockford#.22Good.2C_not_Evil.22 – nickboldt Jan 26 '15 at 21:44
  • 2
    still works with jdk1.7.0_76. i wish maven had a place for "last version compatible with java7", that's twice i've gotten burned with a newest version and searched around for usable versions. and, the github page now says douglas crockford is looking for a new maintainer as of 2015-02-06... – chaqke Feb 18 '15 at 00:17
2

Since your are using JDK1.7, change to the older version will work!

<groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20140107</version>
</dependency>
malajisi
  • 2,165
  • 1
  • 22
  • 18