jackson and jax-rs annotations - rest

I am using Jackson to implement a simple REST API.
Because it is the first time, I would like to be sure that I am following the correct practice.
Looking various examples, I found annotations implemented in the Jackson library such as #JsonProperty.
I found also other annotations that are defined in jax-rs.
It is not clear to me when Jackson ends and jax-rs starts and viceversa.
Is it ok to implement the API using both the annotations ?
Is there an overlapping or are always used to define different characteristics of the API?

JAX-RS is a specification for creating REST web services in Java. JAX-RS requires an implementation such as Jersey, RESTEasy or Apache CXF.
Jackson is a popular JSON parser for Java and can be integrated with JAX-RS using the jackson-jaxrs-providers multi-module project.
While JAX-RS annotations allows you to map classes and methods to handle HTTP requests, Jackson annotations allows you to map Java classes to JSON objects and vice versa.

Related

Akka-HTTP vs JAX-RS

I recently started learning Akka-HTTP and struggling to get one answer.
We know that libraries like Jersey, RestEasy follows a common interface/APIs which is JAX-RS.
And Akka-HTTP is also a suite of libraries. So, does Akka-HTTP also follow JAX-RS?
If not, then how is Akka-HTTP different from JAX-RS?
Any answer to it will be highly appreciated. Thanks in advance.
JAX-RS is just a specification; Jersey, RestEasy etc. are just different implementations of this specification.
Akka-http does not implement JAX-RS; furthermore, equivalent mappings in JAX-RS and Akka-http would be written in completely different code styles:
API's written with JAX-RS are regular methods annotated with annotations
API's written with Akka-http are using router functions instead of annotations and communicate with actors (more about actor model here)

what exactly is JAX-RS?

I am learning the REST architecture these days. I have developed many small small projetcs using jersey. My question is what exaclty is JAX_RS ? I understand that JAX-RS is a set of interfaces (all the javax.ws.rs.* classes) which contains annotations like GET,POST and a lot more. Jersey is one of the bundle which has classes which implement those methods. My doubt is if we download java , do the JAX_RS interfaces come with that ? I have used maven to build REST. There i have seen a lot of entries being added to pom which does my job, but i want to get the actual feel of what exactly is this JAX-RS. Any help is appreciated ! sorry if this is foolish !
JAX-RS is just a specification. A specification specifies how such a framework should work (in a PDF file), and provides different Java interfaces and annotations and enums (like javax.ws.rs.* classes), but no functional code.
The URL for JAX-RS specification are:
JAX-RS 1.1 (you probably use this one) https://jcp.org/en/jsr/detail?id=311
JAX-RS 2.0 https://jcp.org/en/jsr/detail?id=339
Along with the specification there are implementations of that specification, which is functional code (java jars), that you can use in your applications. Such implementations are JERSEY and RestEasy (usually applications use only one).
Now what you need is a JAX-RS tutorial. Take the first two results from google:
http://docs.oracle.com/javaee/6/tutorial/doc/giepu.html (I find this one very good)
http://www.vogella.com/tutorials/REST/article.html (this one is very comprehensive, IMHO)

Is it possible to have a class support both a JAX-RS service and JAX-WS service?

I've created a RESTful web service using jersey and JAX-RS annotations. It's also documented using enunciate and looks great. However, SOAP support has been requested as an option. I noticed in this outdated enunciate example JAX-WS and JAX-RS annotations in the same class. Is this possible? I've tried it myself and enunciate generates documentation correctly, but the services don't actually work.
I'd prefer to have the exact same class support both interfaces rather than two separate classes (one soap one rest) pointing to the business logic class. This would prevent possibly having code in two places.
Here's the example on outdated software versions:
http://docs.codehaus.org/display/ENUNCIATE/A+Rich+Web+service+API+for+Spring
I'm using
Jersey 1.8
Spring 3.0.5
Weblogic 11g
Thanks!
/Chip
I'm not sure what might not be working, but a lot of the Enunciate example modules use both the SOAP and REST annotations on the same class.
Here's one for Jersey/JAX-WS.
Here's one for JBoss WS/RestEasy.
Here's one for CXF.
We ended up making a separate service for SOAP than the REST service. We also found it best to have interfaces for each that enunciate could generate from. This way we could control what documentation it generated. It also started functioning smoother. Still having a problem with the namespaces though as they're all default and ns0 is generated but enunciate links are to ns2/3/4/5/etc. So many links are broken.

JAX-RS support for file upload

I researched ways to write a file upload application. The examples either make use of Jersey or RESTEasy specific annotations to implement the application.
Is there no support for a file upload in the JAX-RS spec itself? Do I have to import Jersey or RESTEasy specific classes to get this to work?
You could develop your own JAX-RS impl-agnostic Multipart support (develop a JAX-RS message-body reader/writer and your own Java representation of the multipart entity) - essentially duplicating what Jersey or RESTEasy provide through their proprietary API already, if JAX-RS portability is of high importance to you.

What's a JAX-RS implementation?

I have been trying to figure out how to use JAX-RS for quite some time. I started from the very basic concepts and then to gradually understand the annotation styled programming, the meaning of #Path, #Get, #Post, etc.
To my understanding, as to what has been mentioned in a lot of places, JAX-RS is a framework that focuses on applying Java annotations to plain Java objects (Page 27, Bill Burke, RESTful Java).
I have then got confused beyond this point. If JAX-RS in itself is a framework that defines APIs dealing with annotations in order to implement RESTful web service, what's the meaning of "implementation of JAX-RS" such as "Jersey" and "JBoos Resteasy". Another layer on top of JAX-RS? Why do we need them?
Could someone provide me some insights about it? Many thanks!!!
JAX-RS is a standard defined in Java Specification Request 311 (JSR-311) and Jersey / RESTEasy are implementations of it.
Being implementations mean that the spec says "if you put #GET("/foo") on a method (bar()), you may access data X" - now in an app server, someone needs to go in and actually read your deployed code, parse the byte code with the #GET annotation and then if the user actually browses to e.g. http://localhost/foo get this web request to reach bar() and translate the return value of bar() into a http answer (e.g in XML or JSON representation).
So the spec with the name "JAX-RS" only provides the syntax and semantics of e.g. #GET, but the work of parsing requests, calling the right methods, marshalling the result values etc. need to be done by a package that implements the Spec.
Work on the version 2.0 of the standard has started as JRS-339.
See also http://en.wikipedia.org/wiki/Jax-rs
JAX-RS is a specification for RESTful Web Services with Java. There is a reference implementation that is included in Java EE but since it is a specification, other frameworks can be written to implement the spec, and that includes Jersey, Resteasy, and others.