diff --git a/autobahn/src/main/java/io/crossbar/autobahn/wamp/interfaces/ISerializer.java b/autobahn/src/main/java/io/crossbar/autobahn/wamp/interfaces/ISerializer.java index 88dd6d83..e8cc63f5 100644 --- a/autobahn/src/main/java/io/crossbar/autobahn/wamp/interfaces/ISerializer.java +++ b/autobahn/src/main/java/io/crossbar/autobahn/wamp/interfaces/ISerializer.java @@ -39,6 +39,10 @@ public ISerializer(JsonFactory factor) { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } + public ISerializer(ObjectMapper objectMapper) { + mapper = objectMapper; + } + public byte[] serialize(List message) { try { return mapper.writeValueAsBytes(message); diff --git a/autobahn/src/main/java/io/crossbar/autobahn/wamp/interfaces/ITransport.java b/autobahn/src/main/java/io/crossbar/autobahn/wamp/interfaces/ITransport.java index 83e7e25b..20b2e1ba 100644 --- a/autobahn/src/main/java/io/crossbar/autobahn/wamp/interfaces/ITransport.java +++ b/autobahn/src/main/java/io/crossbar/autobahn/wamp/interfaces/ITransport.java @@ -28,4 +28,6 @@ public interface ITransport { void abort() throws Exception; void setOptions(TransportOptions options); + + TransportOptions getOptions(); } diff --git a/autobahn/src/main/java/io/crossbar/autobahn/wamp/serializers/JSONSerializer.java b/autobahn/src/main/java/io/crossbar/autobahn/wamp/serializers/JSONSerializer.java index 9f45afbc..6299b7fb 100644 --- a/autobahn/src/main/java/io/crossbar/autobahn/wamp/serializers/JSONSerializer.java +++ b/autobahn/src/main/java/io/crossbar/autobahn/wamp/serializers/JSONSerializer.java @@ -13,6 +13,7 @@ import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.databind.ObjectMapper; import io.crossbar.autobahn.wamp.interfaces.ISerializer; @@ -24,6 +25,9 @@ public class JSONSerializer extends ISerializer { public JSONSerializer() { super(new JsonFactory()); } + public JSONSerializer(ObjectMapper objectMapper) { + super(objectMapper); + } @Override public boolean isBinary() { diff --git a/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/NettyWebSocket.java b/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/NettyWebSocket.java index 1441f6b8..a63be8c5 100644 --- a/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/NettyWebSocket.java +++ b/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/NettyWebSocket.java @@ -229,6 +229,11 @@ public void setOptions(TransportOptions options) { "Not implemented yet, provide options using connect() instead"); } + @Override + public TransportOptions getOptions() { + return mOptions; + } + private ByteBuf toByteBuf(byte[] bytes) { return Unpooled.copiedBuffer(bytes); } diff --git a/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/NettyWebSocketClientHandler.java b/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/NettyWebSocketClientHandler.java index 46611264..e8d32fe3 100644 --- a/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/NettyWebSocketClientHandler.java +++ b/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/NettyWebSocketClientHandler.java @@ -11,6 +11,7 @@ package io.crossbar.autobahn.wamp.transports; +import com.fasterxml.jackson.databind.ObjectMapper; import io.crossbar.autobahn.utils.ABLogger; import io.crossbar.autobahn.utils.Globals; import io.crossbar.autobahn.utils.IABLogger; @@ -176,7 +177,8 @@ private ISerializer initializeSerializer(String negotiatedSerializer) throws Exc case CBORSerializer.NAME: return new CBORSerializer(); case JSONSerializer.NAME: - return new JSONSerializer(); + ObjectMapper objectMapper = mTransport.getOptions().getObjectMapper(); + return objectMapper == null ? new JSONSerializer() : new JSONSerializer(objectMapper); case MessagePackSerializer.NAME: return new MessagePackSerializer(); default: diff --git a/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/RawSocket.java b/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/RawSocket.java index 4d82cb19..e4b06fe3 100644 --- a/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/RawSocket.java +++ b/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/RawSocket.java @@ -111,4 +111,9 @@ public void abort() throws Exception { public void setOptions(TransportOptions options) { } + + @Override + public TransportOptions getOptions() { + throw new UnsupportedOperationException("Not available"); + } } diff --git a/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/WebSocket.java b/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/WebSocket.java index f8019f04..cf66ccad 100644 --- a/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/WebSocket.java +++ b/autobahn/src/main/java/io/crossbar/autobahn/wamp/transports/WebSocket.java @@ -155,6 +155,11 @@ public void setOptions(TransportOptions options) { mConnection.setOptions(webSocketOptions); } + @Override + public TransportOptions getOptions() { + throw new UnsupportedOperationException("Not available"); + } + private ISerializer initializeSerializer(String negotiatedSerializer) throws Exception { switch (negotiatedSerializer) { case CBORSerializer.NAME: diff --git a/autobahn/src/main/java/io/crossbar/autobahn/wamp/types/TransportOptions.java b/autobahn/src/main/java/io/crossbar/autobahn/wamp/types/TransportOptions.java index 3761fc76..c23a19ba 100644 --- a/autobahn/src/main/java/io/crossbar/autobahn/wamp/types/TransportOptions.java +++ b/autobahn/src/main/java/io/crossbar/autobahn/wamp/types/TransportOptions.java @@ -11,10 +11,13 @@ package io.crossbar.autobahn.wamp.types; +import com.fasterxml.jackson.databind.ObjectMapper; + public class TransportOptions { private int mMaxFramePayloadSize; private int mAutoPingInterval; private int mAutoPingTimeout; + private ObjectMapper objectMapper; public TransportOptions() { mMaxFramePayloadSize = 128 * 1024; @@ -54,6 +57,12 @@ public int getAutoPingInterval() { return mAutoPingInterval; } + public ObjectMapper getObjectMapper() {return objectMapper;} + + public void setObjectMapper(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + public void setAutoPingTimeout(int seconds) { mAutoPingTimeout = seconds; }