Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom ObjectMapper feature #552

Merged
merged 8 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> message) {
try {
return mapper.writeValueAsBytes(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public interface ITransport {
void abort() throws Exception;

void setOptions(TransportOptions options);

TransportOptions getOptions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import com.fasterxml.jackson.core.JsonFactory;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.crossbar.autobahn.wamp.interfaces.ISerializer;


Expand All @@ -24,6 +25,9 @@ public class JSONSerializer extends ISerializer {
public JSONSerializer() {
super(new JsonFactory());
}
public JSONSerializer(ObjectMapper objectMapper) {
super(objectMapper);
}

@Override
public boolean isBinary() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,9 @@ public void abort() throws Exception {
public void setOptions(TransportOptions options) {

}

@Override
public TransportOptions getOptions() {
throw new UnsupportedOperationException("Not available");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down