Videos
Then don't write it to a file!
byte[] buf = mapper.writeValueAsBytes(user);
return ResponseEntity
.ok()
.contentLength(buf.length)
.contentType(
MediaType.parseMediaType("application/octet-stream"))
.body(new InputStreamResource(new ByteArrayInputStream(buf)));
EDIT
To prompt browser for .json file type add a header
.header("Content-Disposition", "attachment; filename=\"any_name.json\"")
you dont need to create a file, just convert the object to json using Gson,
Gson gson = new Gson ();
String jsonString = gson.toJson (user);
As far as I can tell (in December 2013) ...
Douglas Crockford's master source repository for "json.org" is now on GitHub - https://github.com/douglascrockford/JSON-java. (The GIT history starts in 2010, and the latest change in "master" is a couple of weeks ago.)
Paul Merlin (aka "eskatos") has Mavenized the code: https://github.com/eskatos/org.json-java
Binary "org.json" JAR files are "regularly" built from Paul Merlin's tree and pushed to Maven Central. You can find them via the "here" link in Paul's README.md file; see the line above.
There are other older (pre-2010) binary releases of the "org.json" JAR file in Maven Central under various guises; review the search results for this link" http://mvnrepository.com/search.html?query=org.json.
The copyright dates in the "org.json" source code don't mean much. They clearly aren't updated when the code is updated. However, Douglas Crockford does update the @version javadoc tags, at least in some commits.
UPDATE (December 2016)
As of some time in 2015, Douglas Crockford has passed ownership of the Github repository to Sean Leary. The old Github URL for the project now redirects to https://github.com/stleary/JSON-java. The project continues to be relatively active.
See also: Where has json.org java library gone?
I would recommend using json-simple or one of the other JSON libraries for Java that have developed. This has features the JSON.org API lacks (and I think it will stay that way).
For instance, the json-simple version of JSONObject implements Map and JSONArray implements List. It also has other features, like a SAX-style API.
Download the ZIP file from this URL and extract it to get the Jar. Add the Jar to your build path. To check the available classes in this Jar use this URL.
To Add this Jar to your build path Right click the Project > Build Path > Configure build path> Select Libraries tab > Click Add External Libraries > Select the Jar file Download
I hope this will solve your problem
You should take the json implementation from here : http://code.google.com/p/json-simple/ .
- Download the *.jar
- Add it to the classpath (right-click on the project, Properties->Libraries and add new JAR.)
The two most popular and fully-featured Java JSON libraries according to Maven Repository are:
- GSON (2.4)
- Jackson (2.6)
and jars for both are accessible via Maven:
- Gson requires
gson-2.4.jar(group idcom.google.code.gson, artifact idgson - Jackson requires
jackson-databind-2.6.2.jar(group idcom.fasterxml.jackson.core, artifactjackson-databind), as well as 2 supporting jars (jackson-corefor streaming parser,jackson-annotationsfor annotation suport)
Jars that you listed are for other lesser commonly used packages (one for json-lib, http://json-lib.sourceforge.net/ is pretty old; other I don't even know what it is), so I would not recommend you use them.
The missing class in the NoClassDefFoundError is located in commons-lang.jar from apache.
It can be downloaded here.