2013-02-06 1 views
1

그리즐리 웹 서버에서 JSON을 생성하기 위해 좋은 시간을 보냈습니다. Maven quickstart grizzly Archetype을 사용하여 JSON을 생성 할 수 없음

세부 사항, 인 IntelliJ를 사용하여 받는다는 전형에서 생성 :

groupId untitled3 
artifactId untitled3 
version 1.0-SNAPSHOT 
archetypeGroupId org.glassfish.jersey.archetypes 
archetypeArtifactId jersey-quickstart-grizzly2 
archetypeVersion 2.0-m05 

모든 온라인 예 JSON 그러나,이 저지 2.X에서 작동하지 않습니다

rc.put(JSONConfiguration.FEATURE_POJO_MAPPING, true); 

를 사용 가능하게 넣어 방법은 존재하지 않습니다 .

메인 클래스에는 JSON이 작동하도록 코드 줄의 주석 처리를 제거하는 방법에 대한 지침이 있습니다. 이 코드 줄의 주석을 제거 할 때 사용한 메서드가 존재하지 않습니다.

public static HttpServer startServer() { 
    // create a resource config that scans for JAX-RS resources and providers 
    // in untitled2 package 
    final ResourceConfig rc = new ResourceConfig().packages("untitled2"); 

    // uncomment the following line if you want to enable 
    // support for JSON on the service (you also have to uncomment 
    // dependency on jersey-media-json module in pom.xml) 
    // -- 
    rc.addModule(org.glassfish.jersey.media.json.JsonJaxbModule); 

    // create and start a new instance of grizzly http server 
    // exposing the Jersey application at BASE_URI 
    return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc); 
} 

내가이 오류를 얻을 POJO 객체에서 JSON 응답을 제공 할 때 : 정말보고 시작하는 아무 생각도 없어

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=application/json, type=class com.example.JsonPost, genericType=class com.example.JsonPost. 

합니다. 내가 봤 거든, 설명서를 보면서 사용자 그룹을 살펴 보았습니다 ...

답변

2

POM의 종속성을 주석 처리 해제했는지 확인하십시오.

rc.addModules(new org.glassfish.jersey.media.json.JsonJaxbModule()); 

및 자원의 올바른 @Produces 주석을 포함해야합니다 : : 다음에 addModule 전화를 변경 당신이 그것을 할 방법을 알고 때 SOOOOOO 쉽고 분명

@Produces(MediaType.APPLICATION_JSON) 
+0

합니다. 나는 진지해, 나는이 정보를 찾을 수 없었다. – OakNinja

+0

그리고 도와 주셔서 정말 고마워요! – OakNinja

관련 문제