Skip to content

Commit 7134b0e

Browse files
committed
JCBC-1588: Give TypeRef overload of JsonSerializer a default "unsupported" impl
To make it easier for the application to create a custom JsonSerializer, provide a default implementation for the overload that takes a TypeRef. The impetus for this change is that trying to write a custom serializer for MessagePack required some non-trivial marshalling and casting, to turn the TypeRef into something usable by the MessagePack Java library. The overload is only needed if the application is using contentAs(new TypeRef<..>{}) - which is an unusual requirement. Change-Id: I9c084174a2b18fdde73bfee27f9729e71601dc82 Reviewed-on: http://review.couchbase.org/122259 Tested-by: Build Bot <[email protected]> Reviewed-by: Michael Nitschinger <[email protected]>
1 parent 453359e commit 7134b0e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

java-client/src/main/java/com/couchbase/client/java/codec/JsonSerializer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.couchbase.client.java.codec;
1818

19+
import com.couchbase.client.core.error.DecodingFailureException;
20+
1921
/**
2022
* The {@link JsonSerializer} handles the serialization and deserialization of raw json data into java objects.
2123
*/
@@ -47,6 +49,7 @@ public interface JsonSerializer {
4749
* @param <T> the type to deserialize into.
4850
* @return the deserialized output.
4951
*/
50-
<T> T deserialize(TypeRef<T> target, byte[] input);
51-
52+
default <T> T deserialize(TypeRef<T> target, byte[] input) {
53+
throw new DecodingFailureException(getClass().getSimpleName() + " does not support decoding via TypeRef.");
54+
}
5255
}

0 commit comments

Comments
 (0)