FasterXML / jackson-dataformats-binary

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

Cannot deserialize byte[] from avro schema #375

Closed MelleD closed 1 year ago

MelleD commented 1 year ago
public class TestDto {

   @JsonProperty( "id" )
   private Long id;

   public Long getId() {
      return id;
   }

   public void setId( final Long id ) {
      this.id = id;
   }

   public TestDto id( final Long id ) {
      setId( id );
      return this;
   }
}

With the AvroMapper i can serialize the object but cannot deserialize it.

What i tried, both method not working

   private AvroSchema generateAvroSchema( final Object root ) throws JsonMappingException {
      AvroMapper avroMapper = new AvroMapper();
      final AvroSchemaGenerator gen = new AvroSchemaGenerator();
      gen.enableLogicalTypes();
      avroMapper.acceptJsonFormatVisitor( root.getClass(), gen );

      return gen.getGeneratedSchema();
   }
         final byte[] raw1 = avroMapper.writer().with( jacksonAvroSchema ).writeValueAsBytes( rootObject );
         final Object obj1 = avroMapper.readerFor( rootObject.getClass() ).with( jacksonAvroSchema ).readValue( raw1 );
         final byte[] encoded = avroMapper.writer( jacksonAvroSchema ).writeValueAsBytes( rootObject );
         final Object dto = avroMapper.reader( jacksonAvroSchema ).readValue( encoded );

Always same error:

java.lang.NoSuchFieldError: EXACT_FLOATS

    at com.fasterxml.jackson.dataformat.avro.AvroParser.<clinit>(AvroParser.java:72)
    at com.fasterxml.jackson.dataformat.avro.AvroFactory._createParser(AvroFactory.java:435)
    at com.fasterxml.jackson.dataformat.avro.AvroFactory.createParser(AvroFactory.java:371)
    at com.fasterxml.jackson.dataformat.avro.AvroFactory.createParser(AvroFactory.java:358)
    at com.fasterxml.jackson.dataformat.avro.AvroFactory.createParser(AvroFactory.java:19)
    at com.fasterxml.jackson.databind.ObjectReader.createParser(ObjectReader.java:1075)
    at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1529)

Whats wrong?

cowtowncoder commented 1 year ago

That sounds like a version incompatibility: StreamReadCapability.EXACT_FLOATS comes from jackson-core so you probably have too old version of jackson-core in classpath: its minor version must be same or higher than that of jacson-dataformat-avro (recommended to have same minor version).

MelleD commented 1 year ago

@cowtowncoder thanks will check that on monday

MelleD commented 1 year ago

That sounds like a version incompatibility: StreamReadCapability.EXACT_FLOATS comes from jackson-core so you probably have too old version of jackson-core in classpath: its minor version must be same or higher than that of jacson-dataformat-avro (recommended to have same minor version).

Jip you are right checked it with2.14.2 and 2.15.0 both works

cowtowncoder commented 1 year ago

Thank you for verifying @MelleD .