I had the same problem that I solved in 3 steps with Jackson in Netbeans / Glashfish btw.
1) Requirements:
Some of the boxes I used:
commons-codec-1.10.jar commons-logging-1.2.jar log4j-1.2.17.jar httpcore-4.4.4.jar jackson-jaxrs-json-provider-2.6.4.jar avalon-logkit-2.2.1.jar javax.servlet-api-4.0.0-b01.jar httpclient-4.5.1.jar jackson-jaxrs-json-provider-2.6.4.jar jackson-databind-2.7.0-rc1.jar jackson-annotations-2.7.0-rc1.jar jackson-core-2.7.0-rc1.jar
If I missed any of the cans above, you can download from Maven here http://mvnrepository.com/artifact/com.fasterxml.jackson.core
2) The Java class where you are sending the message. First, convert with Entity user Jackson to Json, and then send him to your vacation class.
import com.fasterxml.jackson.databind.ObjectMapper; import ht.gouv.mtptc.siiv.model.seguridad.Usuario; import java.io.IOException; import java.io.UnsupportedEncodingException; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.json.simple.JSONObject; public class PostRest { public static void main(String args[]) throws UnsupportedEncodingException, IOException {
3) Java Class Rest, where you want to get Entity JPA / Hibernate. Here with your MediaType.APPLICATION_JSON you get the object like this:
"Identifier": 99 , "usuarioPadre": zero, "nickname": zero, "clave": zero, "Nombre": NULL, "apellidos": zero, "isLoginWeb": zero, "isLoginMovil": zero, "Estado ": null," correoElectronico ": null," imagePerfil ": null," Perfil ": null," urlCambioClave ": null," Telefono ": null," Celular ": null" isFree ": null," proyectoUsuarioList ": null , "cuentaActiva": null, "keyUser": null, "isCambiaPassword": null, "videoList": null, "idSocial": null, "tipoSocial": null, "idPlanActivo": null, "cantidadMbContratado": null, " cantidadMbConsumido ": null," cuotaMb ": null," fechaInicio ": null," fechaFin ": null}"
import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.apache.log4j.Logger; @Path("/seguridad") public class SeguridadRest implements Serializable { @POST @Path("obtenerEntidad") @Consumes(MediaType.APPLICATION_JSON) public JSONArray obtenerEntidad(Usuario u) { JSONArray array = new JSONArray(); LOG.fatal(">>>Finally this is my entity(JPA/Hibernate) which will print the ID 99 as showed above :" + u.toString()); return array;
Some tips. If you have problems starting the network after using this code, possibly due to @Consumes in XML ... you should set it as @Consumes(MediaType.APPLICATION_JSON)