- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在整理 OSGi R7、OpenAPI 和 jsonSchema 的一个简短的 REST 演示。一切正常,除了 Postman 给出以下错误:
No message body writer has been found for class com.ovloop.masterdata.party.pojo.provider.Person, ContentType: application/json
package com.xyz.masterdata.party.rest;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.http.whiteboard.propertytypes.HttpWhiteboardResource;
import org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsResource;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.xyz.masterdata.party.pojo.provider.Person;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
@JaxrsResource
@HttpWhiteboardResource(pattern = { "" }, prefix = "")
@Path("/person")
@Tags(@Tag(name = "test", description = ""))
@OpenAPIDefinition(info = @Info(description = "Person Service", version = "1.0", title = ""))
@Component(service = PersonRestImpl.class, immediate = true, property = { "service.exported.interfaces=*",
"service.intents=osgi.async", "service.intents=jaxrs", "osgi.basic.timeout=50000" })
public class PersonRestImpl {
@GET
@Path("/person")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Get person with key", description = "Get person with key")
public Person getPerson(@PathParam("person") Long personId) {
Person person = new Person();
person.setPersonId("3245234");
person.setFirstName("Tom");
person.setLastName("Petty");
person.setAge(65);
return person;
}
@GET
@Path("/persons")
@Operation(summary = "Get persons", description = "Get list of persons")
public Response getPersons() {
Person person = new Person();
person.setPersonId("3245234");
person.setFirstName("Tom");
person.setLastName("Petty");
person.setAge(65);
List<Person> persons = new ArrayList<Person>();
persons.add(person);
Gson jsonConverter = new GsonBuilder().create();
return Response.status(Status.ACCEPTED).entity(jsonConverter.toJson(persons)).build();
}
@DELETE
@Path("/delete")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "delete person", description = "delete person")
public boolean deletePerson(@PathParam("person") long personId) {
return true;
}
@POST
@Path("/create")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Create Person", description = "Create Person")
public Person postPerson(Person person) {
// if (person.personId > 0) {
// personDao.update(person);
// return person;
// } else {
// long id = personDao.save(person);
// person.personId = 1;
// return person;
// }
return person;
}
}
package com.xyz.masterdata.party.pojo.provider;
import java.util.HashMap;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
/**
* Person
* <p>
*
*
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
"personId",
"age",
"fullName",
"firstName",
"lastName"
})
public class Person {
/**
*
* (Required)
*
*/
@JsonProperty("personId")
private String personId;
/**
* Age in years
*
*/
@JsonProperty("age")
@JsonPropertyDescription("Age in years")
private Integer age;
/**
*
* (Required)
*
*/
@JsonProperty("fullName")
private String fullName;
@JsonProperty("firstName")
private String firstName;
@JsonProperty("lastName")
private String lastName;
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
/**
*
* (Required)
*
*/
@JsonProperty("personId")
public String getPersonId() {
return personId;
}
/**
*
* (Required)
*
*/
@JsonProperty("personId")
public void setPersonId(String personId) {
this.personId = personId;
}
public Person withPersonId(String personId) {
this.personId = personId;
return this;
}
/**
* Age in years
*
*/
@JsonProperty("age")
public Integer getAge() {
return age;
}
/**
* Age in years
*
*/
@JsonProperty("age")
public void setAge(Integer age) {
this.age = age;
}
public Person withAge(Integer age) {
this.age = age;
return this;
}
/**
*
* (Required)
*
*/
@JsonProperty("fullName")
public String getFullName() {
return fullName;
}
/**
*
* (Required)
*
*/
@JsonProperty("fullName")
public void setFullName(String fullName) {
this.fullName = fullName;
}
public Person withFullName(String fullName) {
this.fullName = fullName;
return this;
}
@JsonProperty("firstName")
public String getFirstName() {
return firstName;
}
@JsonProperty("firstName")
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public Person withFirstName(String firstName) {
this.firstName = firstName;
return this;
}
@JsonProperty("lastName")
public String getLastName() {
return lastName;
}
@JsonProperty("lastName")
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Person withLastName(String lastName) {
this.lastName = lastName;
return this;
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
public Person withAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
return this;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(Person.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
sb.append("personId");
sb.append('=');
sb.append(((this.personId == null)?"<null>":this.personId));
sb.append(',');
sb.append("age");
sb.append('=');
sb.append(((this.age == null)?"<null>":this.age));
sb.append(',');
sb.append("fullName");
sb.append('=');
sb.append(((this.fullName == null)?"<null>":this.fullName));
sb.append(',');
sb.append("firstName");
sb.append('=');
sb.append(((this.firstName == null)?"<null>":this.firstName));
sb.append(',');
sb.append("lastName");
sb.append('=');
sb.append(((this.lastName == null)?"<null>":this.lastName));
sb.append(',');
sb.append("additionalProperties");
sb.append('=');
sb.append(((this.additionalProperties == null)?"<null>":this.additionalProperties));
sb.append(',');
if (sb.charAt((sb.length()- 1)) == ',') {
sb.setCharAt((sb.length()- 1), ']');
} else {
sb.append(']');
}
return sb.toString();
}
@Override
public int hashCode() {
int result = 1;
result = ((result* 31)+((this.firstName == null)? 0 :this.firstName.hashCode()));
result = ((result* 31)+((this.lastName == null)? 0 :this.lastName.hashCode()));
result = ((result* 31)+((this.fullName == null)? 0 :this.fullName.hashCode()));
result = ((result* 31)+((this.personId == null)? 0 :this.personId.hashCode()));
result = ((result* 31)+((this.additionalProperties == null)? 0 :this.additionalProperties.hashCode()));
result = ((result* 31)+((this.age == null)? 0 :this.age.hashCode()));
return result;
}
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if ((other instanceof Person) == false) {
return false;
}
Person rhs = ((Person) other);
return (((((((this.firstName == rhs.firstName)||((this.firstName!= null)&&this.firstName.equals(rhs.firstName)))&&((this.lastName == rhs.lastName)||((this.lastName!= null)&&this.lastName.equals(rhs.lastName))))&&((this.fullName == rhs.fullName)||((this.fullName!= null)&&this.fullName.equals(rhs.fullName))))&&((this.personId == rhs.personId)||((this.personId!= null)&&this.personId.equals(rhs.personId))))&&((this.additionalProperties == rhs.additionalProperties)||((this.additionalProperties!= null)&&this.additionalProperties.equals(rhs.additionalProperties))))&&((this.age == rhs.age)||((this.age!= null)&&this.age.equals(rhs.age))));
}
}
-runfw: org.eclipse.osgi;version=3.13
-runee: JavaSE-1.8
-runprovidedcapabilities: ${native_capability}
-resolve.effective: active
-runproperties: \
osgi.console=,\
osgi.console.enable.builtin=false
-runrequires: \
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.shell)',\
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)',\
osgi.identity;filter:='(osgi.identity=com.xyz.masterdata.application.services)',\
bnd.identity;id='com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider',\
bnd.identity;id='com.fasterxml.jackson.jaxrs.jackson-jaxrs-base',\
bnd.identity;id='com.fasterxml.jackson.core.jackson-databind',\
bnd.identity;id='com.fasterxml.jackson.core.jackson-core',\
bnd.identity;id='com.xyz.masterdata.party.rest',\
bnd.identity;id='com.xyz.masterdata.party.pojo.provider'
-runbundles: \
com.xyz.masterdata.application.services;version=snapshot,\
com.xyz.masterdata.party.rest;version=snapshot,\
com.xyz.masterdata.party.pojo.provider;version=snapshot,\
org.apache.felix.configadmin;version='[1.9.8,1.9.9)',\
org.apache.felix.configurator;version='[1.0.6,1.0.7)',\
org.apache.felix.scr;version='[2.1.10,2.1.11)',\
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
org.apache.aries.javax.jax.rs-api;version='[1.0.0,1.0.1)',\
org.apache.aries.jax.rs.whiteboard;version='[1.0.1,1.0.2)',\
org.apache.felix.gogo.runtime;version='[1.0.10,1.0.11)',\
org.apache.felix.http.jetty;version='[4.0.6,4.0.7)',\
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
org.apache.servicemix.specs.annotation-api-1.3;version='[1.3.0,1.3.1)',\
org.osgi.service.jaxrs;version='[1.0.0,1.0.1)',\
org.osgi.util.function;version='[1.1.0,1.1.1)',\
org.osgi.util.promise;version='[1.1.0,1.1.1)',\
slf4j.api;version='[1.7.25,1.7.26)',\
org.apache.felix.gogo.command;version='[1.0.2,1.0.3)',\
org.apache.felix.gogo.shell;version='[1.0.0,1.0.1)',\
io.swagger.core.v3.swagger-annotations;version='[2.0.7,2.0.8)',\
com.google.gson;version='[2.8.5,2.8.6)',\
com.fasterxml.jackson.core.jackson-annotations;version='[2.9.8,2.9.9)',\
com.fasterxml.jackson.core.jackson-core;version='[2.9.8,2.9.9)',\
com.fasterxml.jackson.core.jackson-databind;version='[2.9.8,2.9.9)',\
com.fasterxml.jackson.jaxrs.jackson-jaxrs-base;version='[2.9.8,2.9.9)',\
com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider;version='[2.9.8, 2.9.9)'
No message body writer has been found for class com.ovloop.masterdata.party.pojo.provider.Person, ContentType: application/json
@GET
@Path("/person")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Get person with key", description = "Get person with key")
public Response getPerson(@PathParam("person") Long personId) {
Person person = new Person();
person.setPersonId("3245234");
person.setFirstName("Tom");
person.setLastName("Petty");
person.setAge(65);
Gson jsonConverter = new GsonBuilder().create();
return Response.status(Status.ACCEPTED).entity(jsonConverter.toJson(person)).build();
}
最佳答案
保罗曾提到注册 JacksonJsonProvider。我的印象是添加 fastxml 的 jackson 提供程序作为必需的包可以解决问题。我改为将其换成 org.apache.aries.jax.rs.jackson,并且一切正常。
下面是我更新的 bndrun 文件:
-runfw: org.eclipse.osgi;version=3.13
-runee: JavaSE-1.8
-runprovidedcapabilities: ${native_capability}
-resolve.effective: active
-runproperties: \
osgi.console=,\
org.osgi.service.http.port=6000,\
osgi.console.enable.builtin=false
-runrequires: \
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.shell)',\
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)',\
bnd.identity;id='org.apache.aries.jax.rs.jackson',\
bnd.identity;id='org.apache.aries.jax.rs.jaxb.json',\
bnd.identity;id='com.xyz.masterdata.party.rest',\
bnd.identity;id='com.xyz.masterdata.party.pojo.provider',\
bnd.identity;id='com.xyz.masterdata.application.services'
-runbundles: \
com.xyz.masterdata.party.rest;version=snapshot,\
com.xyz.masterdata.party.pojo.provider;version=snapshot,\
org.apache.felix.configadmin;version='[1.9.8,1.9.9)',\
org.apache.felix.scr;version='[2.1.10,2.1.11)',\
ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
ch.qos.logback.core;version='[1.2.3,1.2.4)',\
org.apache.aries.javax.jax.rs-api;version='[1.0.0,1.0.1)',\
org.apache.aries.jax.rs.whiteboard;version='[1.0.1,1.0.2)',\
org.apache.felix.gogo.runtime;version='[1.0.10,1.0.11)',\
org.apache.felix.http.jetty;version='[4.0.6,4.0.7)',\
org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
org.apache.servicemix.specs.annotation-api-1.3;version='[1.3.0,1.3.1)',\
org.osgi.service.jaxrs;version='[1.0.0,1.0.1)',\
org.osgi.util.function;version='[1.1.0,1.1.1)',\
org.osgi.util.promise;version='[1.1.0,1.1.1)',\
slf4j.api;version='[1.7.25,1.7.26)',\
org.apache.felix.gogo.command;version='[1.0.2,1.0.3)',\
org.apache.felix.gogo.shell;version='[1.0.0,1.0.1)',\
io.swagger.core.v3.swagger-annotations;version='[2.0.7,2.0.8)',\
com.fasterxml.jackson.core.jackson-annotations;version='[2.9.8,2.9.9)',\
com.fasterxml.jackson.core.jackson-core;version='[2.9.8,2.9.9)',\
com.fasterxml.jackson.core.jackson-databind;version='[2.9.8,2.9.9)',\
com.fasterxml.jackson.jaxrs.jackson-jaxrs-base;version='[2.9.8,2.9.9)',\
com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider;version='[2.9.8,2.9.9)',\
com.xyz.masterdata.application.services;version=snapshot,\
org.apache.felix.configurator;version='[1.0.6,1.0.7)',\
com.fasterxml.jackson.module.jackson-module-jaxb-annotations;version='[2.9.8,2.9.9)',\
org.apache.aries.jax.rs.jackson;version='[1.0.2,1.0.3)',\
javax.json-api;version='[1.1.4,1.1.5)',\
org.apache.cxf.cxf-core;version='[3.3.1,3.3.2)',\
org.apache.cxf.cxf-rt-frontend-jaxrs;version='[3.3.1,3.3.2)',\
org.apache.cxf.cxf-rt-security;version='[3.3.1,3.3.2)',\
org.apache.cxf.cxf-rt-transports-http;version='[3.3.1,3.3.2)',\
org.apache.ws.xmlschema.core;version='[2.2.4,2.2.5)',\
org.apache.aries.jax.rs.jaxb.json;version='[1.0.0,1.0.1)'
关于jersey - OSGi、Jersey 和 "No message body writer has been found for class",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55776973/
我已阅读 Jersey documentation ,并表示 Jersey 在读取实体后自动关闭连接(例如 response.readEntity(SomeObject.class)) 但是当抛出异常
Jersey vs Jersey (Standalone) vs Jersey with Grizzly vs Jersey with Tomcat - for REST services 有什么区别
如何通过 guice 使用非 Jersey 资源和 Jersey 资源? 我希望“/”由普通 servlet 处理。但我希望 Jersey 处理“/users”。 假设我有一个带@Path("/use
我正在尝试使用 Maven、Apache Tomcat 7.0、Eclipse IDE 创建一个基本的 RESTful 应用程序。我在 google 提供的一些示例代码中遇到了 jersey-serv
我已经从 Jersey 1.7 升级到 2.16,但 Jersey 似乎无法找到我的资源(请参阅下面的堆栈)。任何想法发生了什么?我尝试在扩展 ResourceConfig 的自定义应用程序类中初始化
我正在使用 com.yammer.dropwizard.config.Environment addProvider 方法在 Jersey 中注册提供程序。我也有一个自定义提供程序,它执行类似于 Dr
在 Jersey 1.x 中,您可以使用 ContainerRequest.getFormParameters()对表单数据进行请求过滤,但我在 Jersey 2.x 中看不到明显的等价物。我已经实现
我正在使用Jersey的集成Jackson处理将传入的JSON转换为POJO,例如: @POST @Consumes(MediaType.APPLICATION_JSON) public Respon
我正在尝试以编程方式创建 Jersey 资源(没有注释)。我有一个将 Name 和 id 作为输入参数的方法 raiseAlarm。我想从 JSON 输入中获取名称,并且我希望 id 来自路径参数。代
Dropwizard official documentation Jersey 客户端不可测试,有人有 dropwizard Jersey 客户端样本吗? 最佳答案 我发现在 Dropwizard
我一直在寻找解决这个问题的方法,但没有成功。我发现的最新帖子可以追溯到 2010 年。我正在使用带有嵌入式 grizzly 2.2.1 的 Jersey 1.12。 如果我理解正确,除非我将 Jers
我想开发一个 Web API,它将生成和使用 JSON 和 XML 数据。 我已经使用JAXB来支持XML,并且工作正常。现在我想添加 JSON 类型。我研究了不同的教程,所有教程都使用不同的依赖项,
如此处所述:http://wikis.sun.com/display/Jersey/WADL 我在 Tomcat 6 中使用 Jersey 1.4。 我已经尝试了所有可能的带有“/applicatio
我是jax-rs的新手,并且已经用jersey和glassfish构建了Web服务。 我需要的是一种方法,服务启动后即被称为。在这种方法中,我想加载自定义配置文件,设置一些属性,编写日志等等。 我尝试
当客户端请求 Not Acceptable MIME 类型时,如何防止 Jersey 在客户端发送 HTML 页面?我想使用 ExceptionMapper,但我不确定要捕获什么异常,或者这是否是处理
我试图在它的 JSON 被解码后拦截一个资源调用。通过阅读一些论坛和帖子,我发现我可以通过实现 来做到这一点。 org.glassfish.jersey.server.spi.internal.Res
我的 webapp 包含一个库,其中包含一个用 @javax.ws.rs.ext.Provider 注释的类。 .如果存在此类,我的 web 应用程序(在 EAR 中部署为 WAR)将无法启动并显示以
我想自定义404响应,即服务器(不是我)在找不到请求的资源时抛出(或自己抛出一个自定义的WebApplicationException,如果可以测试一个应用程序中是否存在请求的资源)?资源列表存储在某
我有一个受 Shibboleth(SSO 实现)保护的 Jersey API。 Shibboleth 将登录用户的 ID 放入请求属性中。在后端,我使用 Shiro 进行授权。 Shiro 希望了解登
我目前正在使用 Jersey 返回 JSON。我该如何返回 JSONP?例如我当前的RESTful方法是: @GET @Produces(MediaType.APPLICATION_JSON) pub
我是一名优秀的程序员,十分优秀!