FasterXML / FasterXML/jackson-dataformats-binary

'Any' type not supported as a type by protobuf

Open
#199 3 comments 0 reactions 0 assignees View on GitHub
protobuf
Dominant language
Java
Stars
347
Forks
156
Avg merge
3d 3h
Merged PRs (30d)
22

Description

Hi! I have the below generic object that I use as a wrapper around other objects when sending a response.

```
public class Response {
private T data;

public Response() {

}

public T getData() {
return data;
}

public void setData(T data) {
this.data = data;
}
}
```

When I try to generate a byte buffer from the `Response` object with the below code I receive the error, _'Any' type not supported as a type by protobuf_

```
ObjectMapper mapper = new ObjectMapper(new ProtobufFactory());
ProtobufSchemaGenerator generator = new ProtobufSchemaGenerator();
mapper.acceptJsonFormatVisitor(Response.class, generator);
ProtobufSchema schema = generator.getGeneratedSchema();

Response response = new Response<>();

byte[] bytes = mapper.writer(schema).writeValueAsBytes(response);
ByteBuffer buffer = ByteBuffer.wrap(bytes);

session.sendMessage(new BinaryMessage(buffer));
```

Are generics not supported? Would there be an alternative to this generics approach?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.