我有一个返回这种 json 对象的 web 服务:
{
"dossiers": [
{
"id": "2"
},
{
"id": "3"
}
]
}
所以我尝试使用 jersey-client (v1.12) 在 POJO 中反序列化这个答案。
所以这是我当前的代码:
档案POJO.java
@XmlRootElement( name = "dossiers" )
public class DossiersPOJO
{
private List<DossierPOJO> dossiers;
public List<DossierPOJO> getDossiers( )
{
return dossiers;
}
public void setDossiers( List<DossierPOJO> dossiers )
{
this.dossiers = dossiers;
}
}
档案.java
public class DossierPOJO
{
private Long id;
public Long getId( )
{
return id;
}
public void setId( Long id )
{
this.id = id;
}
}
和客户端代码本身:
WebResource siraWebResource = Client.create( ).resource(
"http://localhost:8081/site/rest/path/resources" );
Builder accept = siraWebResource.accept( MediaType.APPLICATION_JSON_TYPE );
// accept.accept( "application/json" );
DossiersPOJO dossierJson = accept.get( DossiersPOJO.class );
但是当我调用 get 时,我得到了这个错误堆栈:
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
26 avr. 2012 17:18:03 com.sun.jersey.api.client.ClientResponse getEntity
GRAVE: A message body reader for Java class fr.paris.lutece.batches.ramen.bean.DossiersPOJO, and Java type class fr.paris.lutece.batches.ramen.bean.DossiersPOJO, and MIME media type application/json was not found
26 avr. 2012 17:18:03 com.sun.jersey.api.client.ClientResponse getEntity
GRAVE: The registered message body readers compatible with the MIME media type are:
*/* ->
com.sun.jersey.core.impl.provider.entity.FormProvider
com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider
com.sun.jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
com.sun.jersey.core.impl.provider.entity.EntityHolderReader
我不知道问题出在哪里,因为我知道我的客户端 POJO 与服务器端完全相同。