0
How can I handle a json using a servlet?
I have a form which I just manipulated with javascript, and it is ready to be sent in JSON format to a servlet, however, I have no idea how to handle a json with this, since it accepts objects in xmlurlform by default. The fact of not being able to use the object in javascript to make all the necessary requests bothers me, even a property contains an array of objects and handling that with xmlurlform would be very uncomfortable
1 Respuesta
+ 1
So you just want to parse JSON data in Java.
Java standard API doesn't have support for JSON but there are multiple open-source libraries which can do that for you. The most popular one is Gson (published by Google) but there are also other options.
If you use a package manager such as Gradle or Maven, you can just add these libraries as dependency to your projects. Alternatively you can download the jar files and place them somewhere in your Java classpath.
https://www.baeldung.com/gson-deserialization-guide
https://www.viralpatel.net/creating-parsing-json-data-with-java-servlet-struts-jsp-json/
https://www.javatpoint.com/how-to-get-value-from-json-object-in-java-example