FasterXML / jackson-dataformats-binary

Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Apache License 2.0
316 stars 136 forks source link

Protobuf - Boolean vs boolean when generating schema from class #104

Closed renpillay closed 7 years ago

renpillay commented 7 years ago

Using the following code to generate a Protobuf schema fails to generate a schema when there's an element in Employee.class of type Boolean. But it generates fine with the type boolean.

ProtobufMapper mapper = new ProtobufMapper()
ProtobufSchema schemaWrapper = mapper.generateSchemaFor(Employee.class)

eg.

public static class Employee
{
    public String name;
    public int age;
    public String[] emails;
    public Employee boss;
    public boolean someBool; // is fine
}

public static class Employee
{
    public String name;
    public int age;
    public String[] emails;
    public Employee boss;
    public Boolean someBool; // is not fine
}

Is this expected, and if so - is there a workaround that does not involve changing the class definition?

cowtowncoder commented 7 years ago

It sounds more like a flaw -- perhaps some checks/handling does not consider wrappers, only primitive types. If so, I think they should.

Thank you for reporting this.

cowtowncoder commented 7 years ago

@renpillay Could you elaborate bit on what you mean by failing to generate schema here? Simple addition of a Boolean valued property does not seem to trigger an exception for me, with 2.9.0. So I assume you are doing something else (or possibly using an old version)?

renpillay commented 7 years ago

Hi @cowtowncoder

I'm using jackson 2.9.3 (com.fasterxml.jackson.dataformat/jackson-dataformat-protobuf).

The exact code I'm using is the following

    public static class Employee
    {
        public String name;
        public int age;
        public String[] emails;
        public Employee boss;
        public Boolean someBool;
    }

   private final ProtobufMapper objectMapper = new ProtobufMapper();

   // Then later on
   ProtobufSchemaGenerator gen = new ProtobufSchemaGenerator();
   ProtobufSchema schema = objectMapper.generateSchemaFor(Employee.class);

At this point, the exception I get is UnsupportedOperationException with the content "'Boolean' type not supported as root type by protobuf"

However, I'm using 2.8.4, so its possible this has been fixed later on. Let me try updating my version.

renpillay commented 7 years ago

Looks like I get the same behaviour on 2.9.0

cowtowncoder commented 7 years ago

@renpillay That test works for me, with master (2.9.0). Same for 2.8. So I can not reproduce the problem: I suspect fix was in 2.8.8 or 2.8.9. Please make sure new version is used and that no old version is accidentally included in classpath.