Error starting with version 3.1.5: JsonValueSerializerWrapper does not support decoding via TypeRef

Looks starting from version 3.1.5 of the client the , when a customer json serializer is provided, the sdk is wrapping the serializer in JsonValueSerializerWrapper, and this did not have an implementation for the method that take a TypeRef object as input. This causing the above error.

<T> T deserialize(TypeRef<T> target, byte[] input)

the initialization code in ClusterEnvironment

private ClusterEnvironment(ClusterEnvironment.Builder builder) {
    **this.jsonSerializer = (JsonSerializer)(builder.jsonSerializer != null ? new JsonValueSerializerWrapper(builder.jsonSerializer) : this.newDefaultSerializer(builder.cryptoManager));**
    this.transcoder = (Transcoder)CbObjects.defaultIfNull(builder.transcoder, () -> {
      return JsonTranscoder.create(this.jsonSerializer);
    this.cryptoManager = Optional.ofNullable(builder.cryptoManager);
1 Like

Hi Anil,

Yup definitely a bug. Tracking as JCBC-1896. I’ll take a closer look tomorrow to see if there’s a workaround.


This will be fixed in Java SDK 3.2.5. In the mean time, a workaround is to get the document content as a byte array and call the custom JsonSerializer yourself. For example:

Replace this:

List<Widget> widgets = collection.get("myWidget")
    .contentAs(new TypeRef<List<Widget>>(){}); 

With this:

JsonSerializer customSerializer = // get it from somewhere

GetResult result = collection.get("myWidget", GetOptions.getOptions()

byte[] contentBytes = result.contentAs(byte[].class);

List<Widget> widgets = customSerializer.deserialize(
    new TypeRef<List<Widget>>(){}, contentBytes);

This also illustrates how getting the document content as a byte array is harder than it should be. Tracking that as JCBC-1898.