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

Getting "type not supported as root type by protobuf" for serialization of short and UUID types #68

Closed
eldadru opened this issue Mar 28, 2017 · 10 comments
Labels
Milestone

Comments

@eldadru
Copy link

eldadru commented Mar 28, 2017

Hi,

I'm trying to serialize to following class to protobuf using jackson dataformats:

public class HeaderTest
{
  @JsonProperty("version")
  private short version;
  @JsonProperty("messageId")
  private UUID messageId;


  public HeaderTest(short version, UUID messageId)
  {
    this.messageId = messageId;
    this.version = version;
  }
  public short getVersion() {
    return version;
  }

  public void setVersion(short version) {
    this.version = version;
  }

  public UUID getMessageId() {
    return messageId;
  }

  public void setMessageId(UUID messageId) {
    this.messageId = messageId;
  }
}

With the following code:

ProtobufMapper mapper = new ProtobufMapper();
**ProtobufSchema schemaWrapper = mapper.generateSchemaFor(HeaderTest.class);**
NativeProtobufSchema nativeProtobufSchema = schemaWrapper.getSource();
String asProtofile = nativeProtobufSchema.toString();

The bold line throws this exception:

java.lang.UnsupportedOperationException: 'Integer' type not supported as root type by protobuf

	at com.fasterxml.jackson.dataformat.protobuf.schemagen.ProtoBufSchemaVisitor._throwUnsupported(ProtoBufSchemaVisitor.java:141)
	at com.fasterxml.jackson.dataformat.protobuf.schemagen.ProtoBufSchemaVisitor.expectIntegerFormat(ProtoBufSchemaVisitor.java:112)
	at com.fasterxml.jackson.databind.ser.std.StdSerializer.visitIntFormat(StdSerializer.java:215)
	at com.fasterxml.jackson.databind.ser.std.NumberSerializers$Base.acceptJsonFormatVisitor(NumberSerializers.java:75)
	at com.fasterxml.jackson.databind.ser.std.NumberSerializers$ShortSerializer.acceptJsonFormatVisitor(NumberSerializers.java:103)
	at com.fasterxml.jackson.dataformat.protobuf.schemagen.ProtobuffSchemaHelper.acceptTypeElement(ProtobuffSchemaHelper.java:49)
	at com.fasterxml.jackson.dataformat.protobuf.schemagen.MessageElementVisitor.getDataType(MessageElementVisitor.java:122)
	at com.fasterxml.jackson.dataformat.protobuf.schemagen.MessageElementVisitor.buildFieldElement(MessageElementVisitor.java:86)
	at com.fasterxml.jackson.dataformat.protobuf.schemagen.MessageElementVisitor.optionalProperty(MessageElementVisitor.java:65)
	at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.depositSchemaProperty(BeanPropertyWriter.java:805)
	at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.acceptJsonFormatVisitor(BeanSerializerBase.java:833)
	at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.acceptJsonFormatVisitor(DefaultSerializerProvider.java:580)
	at com.fasterxml.jackson.databind.ObjectMapper.acceptJsonFormatVisitor(ObjectMapper.java:3641)
	at com.fasterxml.jackson.databind.ObjectMapper.acceptJsonFormatVisitor(ObjectMapper.java:3620)
	at com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper.generateSchemaFor(ProtobufMapper.java:95)

Any ideas why I can't serialize those types? I couldn't find any online resource about that issue.

Thanks

@cowtowncoder
Copy link
Member

I can't say off-hand what could be causing this. Which version is this with?

@eldadru
Copy link
Author

eldadru commented Mar 28, 2017

Currently, 2.8.1 but also tried the latest version 2.9.0.pr2

@cowtowncoder
Copy link
Member

@eldadru then it probably exists in 2.8.7 too. If easy enough would be nice to double-check, but if not this is fine.

@eldadru
Copy link
Author

eldadru commented Mar 29, 2017

Sorry, I already refactored the code

@cowtowncoder cowtowncoder changed the title [Protobuf] Getting "type not supported as root type by protobuf" for serialization of short and UUID types Getting "type not supported as root type by protobuf" for serialization of short and UUID types Mar 29, 2017
@cowtowncoder
Copy link
Member

@eldadru that's ok, I should be able to reproduce this easily.

@cowtowncoder
Copy link
Member

Yes, I can reproduce this. Should work, not sure yet why it does not.

@cowtowncoder
Copy link
Member

Ok. Fixing may take a while since this is part of code I did not write (it's a contribution), and some of the logic is bit difficult to follow. Fix for short is relatively easy (it just needs to be handled like int, basically). And in theory UUID and similar types really should be handled as either String, or, perhaps, byte array (since format supports native binary content).
But for some reason current schema generator is pickier...

@cowtowncoder cowtowncoder added this to the 2.9.0.pr3 milestone Apr 1, 2017
@cowtowncoder
Copy link
Member

There was a bit bigger issue, but things should work significantly better after fix. Will be in 2.9.0.pr3.

@eldadru
Copy link
Author

eldadru commented Apr 1, 2017

@cowtowncoder Thanks!

@cowtowncoder
Copy link
Member

@eldadru Thank you for reporting this: handling was basically wrong and could only support a small number of primitives, regular POJOs and Lists/arrays. What needed to be added was actual handling of typing as indicated by callbacks, so that (for example) date/time values are indicate as types that they would be encoded in JSON (if written as textual timestamps, then String, if long timestamps, 64-bit and so on).

I suspect there may some other rough edges but I hope these can be located and fixed over time as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants