I'd like to create a Java web application on top of Google AppEngine.
What is the best way to develop a REST jSON API?
Do I have to write from scratch a servlet that manages the jSON handling or there is a library or something like the SOAP support for web services?
No need to write a servlet from scratch, use JAX RS, it is easy and simple
http://tugdualgrall.blogspot.com/2010/02/create-and-deploy-jax-rs-rest-service.html
Try RESTEasy. It has superb docs and there nice examples to be found. It integrates with Jackson which is IMO the best JSON lib for java.
If you use jersey then you should have a look at Genson http://owlike.github.io/genson/.
It is a full databinding+streaming java<>json library. And as a bonus with jersey you only need to have genson in your classpath and voila! Everything shall work without any configuration.
the answer here might be what you're looking for. (Gson should be able to both generate and parse JSON)
After some research I think that using jersey is a good
Related
is there any solution other than Moshi, Gson, KotlinX-Serialization to serialize json in Android? We should not add anything to build.gradle while using technology. We should not download a library from here.
Is there a method on Android just like Codable on iOS? Also, I think how we should do this part is important since Converter will be passed when using it with Retrofit.
Does anyone have experience and advice on this subject?
You can use JSONObject for that.
val json = JSONObject("""{"some":"json"}""")
However, easiest is to use one of the third party frameworks you mentioned to do this.
Sorry for my naive question, I am looking for some tools that would automatically convert JSON objects (that are generated in swagger UI) to a Java class objects in Eclipse.
Are there any such tools or plugins that can integrate swagger code with Eclipse Java and Groovy Grails framework. It would save a lot of time by not rewriting a huge amount of Java code every time when I want to change something in JSON objects.
I suggest to use autorest tool to generate code and models. It supports multiple languages including Java. Here is the github repository autorest
Just follow simple steps-
npm install -g autorest
autorest --input-file=https://******url******/swagger/v1/swagger.json --java --namespace=****namespace*****
You can use Google Gson Library in java.
You could use that or Groovys JSONsluprer but I depending on what you're trying to achieve it might just be easiest if you have a swagger to start with swagger codegen https://github.com/swagger-api/swagger-codegen tools and have it make those for you. If not you can always look to investigate how they did it.
I'm quite new to Grails things. here the problem:
I created a simple class exposed as a REST service with grail. (I only use grail for CRUD operation on database).
I have an Java FX application that needs to consume this service to recreate the original object. Is there a clean way to "export" domain class from grails ?
Thx in advance for any help !
You can create common java library for both projects, include in Grails app and JavaFX app. This common library will share common classes. For marshalling/demarshalling JSON you can use Jackson
GSON or Jackson will do what you want.
Take a look at http://grails.org/doc/latest/guide/webServices.html#domainResources.
For example, if you are returning a "book" domain class from your REST service you could use:
render book as JSON
I would just like to ask if there is a way to upload files in GWT WITHOUT using the Google App Engine and Apache Commons archives? I've been searching for ways to upload files in GWT but all of the solutions I find all make use of these two. I would just like to know if there is a way, because our app won't work if we use GAE and Apache Commons... Thank you very much!
Yes, the simplest would be (assuming you are saving files to Blobstore):
On GWT side use FileUpload. Here is an example on how to use it.
On GAE side use BlobStore upload handler.
The other option would be to use gwt-upload with GAE upload handler.
GWT does not have such feature. You need to use some existing library or handle multipart form submits by yourself (FileUpload class). There is for example a gwtupload library which I have used and it worked pretty fine (but it is based on commons-upload AFAIR). There are other libs for sure.
http://code.google.com/p/gwtupload/
I need to convert XML data to Java objects. What would be best practice to convert this XML data to object?
Idea is to fetch data via a web service (it doesn't use WSDL, just HTTP GET queries, so I cannot use any framework) and answers are in XML. What would be best practice to handle this situation?
JAXB is a standard API for doing this: http://java.sun.com/developer/technicalArticles/WebServices/jaxb/
Have a look at XStream. It might not be the quickest, but it is one of the most user friendly and straightforward converters in Java, especially if your model is not complex.
For a JMS project we were marshalling and unmarshalling (going from java to xml and xml to java) XML embedded in TextMessages (string property). We tried JAXB, Jibx, and XMLBeans. We found that XMLBeans worked best for us. Fast, easily configurable, good documentation, and easy Maven integration.
I have used and will continue to use JDOM -> www.jdom.org
Another option is a Sax Parser. It is procedural - i.e. a visitor pattern - but if the xml is fairly lightweight, (and even medium weight) I have found it to be very useful for this.
JAXB API which comes in Java(In built).
I have used JIBX in MQ module. It works very well. Ant config is simple. Used Xsd2Jibx converter to generate the binding files and Java beans from XML schema. Marshalling and un-marshalling allow to specify character-set parameter. It was useful in my project to handle custom character-set. But I found an issue in the binding compiler. If the Java bean has lengthier path name, it generates class file with lengthier file name which will cause issue in Windows XP(it has a maximum file length limit).
I haven't used other APIs. So I am not trying to compare with others. If you decided to use JIBX, I hope this will be helpful.
More details, please refer JIBX website
I've used XStream as well, it is easy to use and customizable. You can add your own custom converters and that was very handy for me...
So surprised more people have not mentioned Jibx. Amazing lib and i think a lot simpler to use than Jaxb. Performance is also fab!
For this you can also consider apache's bitwixt and simple framework for xml