APPLICATION_JSON cannot be resolved or is not a fi

2019-06-25 13:16发布

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.

标签: java json rest
2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-06-25 13:20

In my case it is not working, so if anyone facing the error then try...

import org.springframework.http.MediaType;

It worked for me...

查看更多
迷人小祖宗
3楼-- · 2019-06-25 13:30

Remove this

import java.awt.PageAttributes.MediaType;

and add this

import javax.ws.rs.core.MediaType;
查看更多
登录 后发表回答