Java Jersey Rest服务无法使用Json注释

Java Jersey Rest服务无法使用Json注释,java,json,rest,api,jersey,Java,Json,Rest,Api,Jersey,我有以下课程: ServerStartup.java import java.io.IOException; import com.sun.jersey.api.container.httpserver.HttpServerFactory; import com.sun.jersey.api.core.PackagesResourceConfig; import com.sun.jersey.api.core.ResourceConfig; import com.sun.jersey.api.j

我有以下课程: ServerStartup.java

import java.io.IOException;
import com.sun.jersey.api.container.httpserver.HttpServerFactory;
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.api.core.ResourceConfig;
import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.net.httpserver.HttpServer;

public class ServerStartUp {
static final String BASE_URI = "http://localhost:9999/";
public static void main(String[] args) {


    try {
        final ResourceConfig rc = new PackagesResourceConfig("com.twins.engine");
        rc.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);         
        HttpServer server = HttpServerFactory.create(BASE_URI,rc);
        server.setExecutor(null);
        server.start();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
}
以及下面的类SysInfo.Java

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.twins.engine.model.SysInfo;

@Path("/Sys")
public class General {

@GET
@Path("/info")
@Produces(MediaType.APPLICATION_JSON)
public SysInfo getInfo(){
    SysInfo info = new SysInfo("Monetoring 365");
    return info;
}
}
以及下面的模型类SysInfo.java

public class SysInfo {
private String name;
public SysInfo(String name) {
    this.setName(name);
}

public String getName() {return name;}

public void setName(String name) {this.name = name; }
}
当我运行serverStartup类并导航到以下url时:

我得到了以下例外:

原因:com.sun.jersey.api.MessageException:未找到Java类com.twins.engine.model.SysInfo和Java类型类com.twins.engine.model.SysInfo的消息正文编写器,以及MIME媒体类型text/html ... 还有15个

此外,我还附带了以下JAR作为图像,是否有任何缺少的配置我必须执行

尝试以下操作

final ResourceConfig rc = new PackagesResourceConfig("com.twins.engine");
final Map<String, Object> config = new HashMap<String, Object>();
config.put("com.sun.jersey.api.json.POJOMappingFeature", true);
rc.setPropertiesAndFeatures(config);
HttpServer server = HttpServerFactory.create(BASE_URI,rc);
server.setExecutor(null);
server.start();
final ResourceConfig rc=new PackagesResourceConfig(“com.twins.engine”);
final Map config=new HashMap();
config.put(“com.sun.jersey.api.json.POJOMappingFeature”,true);
rc.setPropertiesAndFeatures(配置);
HttpServer server=HttpServerFactory.create(BASE_URI,rc);
server.setExecutor(空);
server.start();
也许你必须添加jackson mapper


org.codehaus.jackson
杰克逊地图绘制者
1.9.12
org.codehaus.jackson
jackson core asl
1.9.12

我尝试了您添加的更改,但如果出现相同的异常,则无法正常工作error@Twinscode如何运行应用程序?你能通过pom.xml吗?我在ServerStartup.java中运行main。整个项目都在问题描述中发布,我没有pom.xml文件。很可能你正在使用ide运行,不知道类路径中是否有正确的JAR