Skip to content

Commit

Permalink
custom ObjectMapper feature (#552)
Browse files Browse the repository at this point in the history
* Datatype module support to make Jackson recognize Java 8 Date & Time API data types (JSR-310)

* java version changing in ci/cd (8 -> 11)

* fix step's name

* Jackson ObjectMapper's injection

* fix unnecessary field in NettyWebSocket

* fix unnecessary field in NettyWebSocket

* fix init OM in Options

---------

Co-authored-by: GeyntsePV <[email protected]>
  • Loading branch information
pavelvic and GeyntsePV committed Nov 12, 2023
1 parent 1743bb2 commit f8aa7ef
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 1 deletion.
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

0 comments on commit f8aa7ef

Please sign in to comment.