How to use the org.json Java library with Java 7
Asked Answered
T

3

43

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.

Tadich answered 8/12, 2014 at 6:41 Comment(2)
Unsupported major.minor version 52.0 indicates that that library was compiled with Java 8. Can you get the source and recompile the library for your version?Hasp
that's do-able, but kinda' goes around the point of using a package manager...Nevillenevin
S
67

Have you tried using an older version of the package?

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

Staple answered 8/12, 2014 at 8:24 Comment(5)
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.Tadich
@Tadich Well as MichaelT said, if you really want to use the newest version you can compile the sources yourselfStaple
Yep. Understood, but I prefer to manage dependencies through a dependency manager (such as Maven).Tadich
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 - en.wikipedia.org/wiki/Douglas_Crockford#.22Good.2C_not_Evil.22Maidservant
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...Nevillenevin
O
3

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

<groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20140107</version>
</dependency>
Oilcloth answered 24/12, 2015 at 8:30 Comment(1)
where do I add this?Misshapen
M
0

You should use version 20230618 for Java 6 or 7. There were a few older versions where they accidentally broke Java 6, but Java 7 support should be ok until 20230618
org.json json 20230618

See their release notes: https://github.com/stleary/JSON-java/blob/master/docs/RELEASES.md

20231013 First release with minimum Java version 1.8. Recent commits, including fixes for CVE-2023-5072.

20230618 Final release with Java 1.6 compatibility. Future releases will require Java 1.8 or greater.

Manuscript answered 7/2 at 14:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.