我正在尝试使用xtify向Android和iOS发送推送通知。我能够这样做,但是,有效载荷信息似乎对我不起作用。如果我删除了有效负载,请求会成功,但添加有效负载会导致服务器错误。任何人都可以看看我发送的json,并告诉我,如果我做错了什么?
{
"apiKey":"...",
"appKey":"...",
"xids":[
"..."
],
"content":{
"subject":"chat from billy bob",
"message":"hey",
"payload":{
"UserId":"1",
"DeviceId":"9"
}
}
}
以下是服务器返回的错误: HTTP / 1.1 500内部服务器错误 日期:2012年5月30日星期三22:51:51 GMT Content-Type:text / html; charset = utf-8 内容长度:5839 连接:关闭
JBoss Web / 2.1.3.GA - 错误报告
类型异常报告
< b>消息
描述服务器遇到内部错误(),导致无法完成此请求。
异常< / b>
javax.servlet.ServletException: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token at [Source: org.apache.catalina.connector.CoyoteInputStream@210c8d4e; line: 1, column: 199] (through reference chain: com.xtify.api.entities.PushRequest["content"]->com.xtify.api.entities.Content["payload"]) com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:418) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
根本原因
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token at [Source: org.apache.catalina.connector.CoyoteInputStream@210c8d4e; line: 1, column: 199] (through reference chain: com.xtify.api.entities.PushRequest["content"]->com.xtify.api.entities.Content["payload"]) org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163) org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:219) org.codehaus.jackson.map.deser.std.StringDeserializer.deserialize(StringDeserializer.java:44) org.codehaus.jackson.map.deser.std.StringDeserializer.deserialize(StringDeserializer.java:13) org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299) org.codehaus.jackson.map.deser.SettableBeanProperty$MethodProperty.deserializeAndSet(SettableBeanProperty.java:414) org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:697) org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580) org.codehaus.jackson.map.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:299) org.codehaus.jackson.map.deser.SettableBeanProperty$MethodProperty.deserializeAndSet(SettableBeanProperty.java:414) org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:697) org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580) org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704) org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1315) org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419) com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139) com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:474) com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123) com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46) com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153) com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:203) com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483) com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414) com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363) com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353) com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
note JBoss Web / 2.1.3.GA日志中提供了根本原因的完整堆栈跟踪。
答案 0 :(得分:2)
元素类型是JSON而不是数组。因此有效载荷元素应如下所示:
“payload”:“{'key1':'value1','key2':'value2'}”
尝试一下,让我知道它是如何运作的。
迈克尔