私はサーブレットを使用して構成された大気ジャージを使用しています。大気ハンドラーの投稿で、クラスタイプに基づいて、さまざまなタイプのコマンドの抽象オブジェクトを受け取り、ワーカーにリダイレクトしています。
抽象クラス Command があり、さまざまなコマンドがそこから拡張されます
- 始める
- 継続する
- 終わり
別のワーカーにルーティングしたかった投稿で
@POST
def incoming(@PathParam("topic") topic: String, cmd: Command) {
cmd.getCmdType match {
case "Start" =>
cmd.asInstanceOf[Start]
//
case "Continue" =>
cmd.asInstanceOf[Continue]
case "End" =>
cmd.asInstanceOf[End]
}
Command.java
@XmlRoot
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.WRAPPER_OBJECT,
property = "type")
@JsonSubTypes({
@Type(value = Start.class, name = "Start"),
@Type(value = Continue.class, name = "Continue"),
@Type(value = End.class, name = "End")})
public abstract class Command
ジャージを設定しました
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.mypackage</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.websocket.messageContentType</param-name>
<param-value>application/json</param-value>
</init-param>
しかし、ソケットにプッシュしようとすると
var msgJson = {user: userId, eventCode: event, type: "Start"};
var msg = JSON.stringify(msgJson);
subSocket.push(msg);
抽象クラスをインスタンス化する方法がわからないと不平を言います。したがって、サブタイプの注釈は無視されます
Caused by: javax.xml.bind.UnmarshalException: null
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:431) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:368) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:345) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.jersey.json.impl.BaseJSONUnmarshaller.unmarshalJAXBElementFromJSON(BaseJSONUnmarshaller.java:111) ~[jersey-json-1.14.jar:1.14]
at com.sun.jersey.json.impl.BaseJSONUnmarshaller.unmarshalFromJSON(BaseJSONUnmarshaller.java:100) ~[jersey-json-1.14.jar:1.14]
at com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider.readFrom(JSONRootElementProvider.java:129) ~[jersey-json-1.14.jar:1.14]
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:111) ~[jersey-core-1.14.jar:1.14]
... 41 common frames omitted
Caused by: com.sun.istack.SAXParseException2: Unable to create an instance of mypackage.Command
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:647) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:258) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.createInstance(UnmarshallingContext.java:614) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.StructureLoader.startElement(StructureLoader.java:185) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.XsiTypeLoader.startElement(XsiTypeLoader.java:80) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.ProxyLoader.startElement(ProxyLoader.java:60) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:486) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:464) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:75) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:247) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:181) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:366) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
... 46 common frames omitted
Caused by: javax.xml.bind.UnmarshalException: Unable to create an instance of mypackage.AbstractCommand
... 58 common frames omitted
Caused by: java.lang.InstantiationException: null
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48) ~[na:1.7.0_15]
at java.lang.reflect.Constructor.newInstance(Constructor.java:525) ~[na:1.7.0_15]
at com.sun.xml.bind.v2.ClassFactory.create0(ClassFactory.java:122) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.createInstance(ClassBeanInfoImpl.java:269) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.createInstance(UnmarshallingContext.java:608) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
... 55 common frames omitted