Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

APPLICATION_JSON cannot be resolved or is not a field

Tags:

java

json

rest

I have a problem producing JSON in my application.

I'm trying a tutorial about Consuming Java Restful Web Service with AngularJS. I've created a dynamic web project as my RESTful server and then added the following libraries:

  • asm-3.3.1.jar
  • jackson-core-asl-1.9.9.jar
  • jackson-jaxrs-1.9.9.jar
  • jackson-mapper-asl-1.9.9.jar
  • jackson-xc-1.9.9.jar
  • jersey-bundle-1.8.jar
  • jersey-bundle-1.9.jar
  • jersey-client-1.9.jar
  • jersey-core-1.9.jar
  • jersey-json-1.9.jar
  • jersey-media-json-jettison-2.4.jar
  • jersey-server-1.9.1.jar
  • jersey-servlet-1.12.jar
  • jettison-1.3.3.jar
  • jsr311-api-1.1.1.jar

Here is the service :

package ws;

import java.awt.PageAttributes.MediaType;
import java.util.*;

import javax.ws.rs.*;
import javax.ws.rs.core.*;

import entities.Prospect;

@Path("prospect")
public class ProspectRestful {

    @GET
    @Path("findall")
    @Produces(MediaType.APPLICATION_JSON)
    public List<Prospect> findAll(){

        List<Prospect> result = new ArrayList<Prospect>();

        result.add(new Prospect(35, "Name 35", "last35"));
        result.add(new Prospect(36, "Name 36", "last36"));


        return result;
    }
}

But I'm getting this error:

APPLICATION_JSON cannot be resolved or is not a field.

I've seen in another question that jersey-media-json-jettison-2.4.jar should be there so I added it but no sign.

I'm sure I'm not using a Maven project, in the same tutorial they didn't use Maven either.

like image 838
Ghita Avatar asked Nov 11 '15 09:11

Ghita


1 Answers

Remove this

import java.awt.PageAttributes.MediaType;

and add this

import javax.ws.rs.core.MediaType;
like image 113
shazin Avatar answered Nov 12 '22 07:11

shazin