2

This is my main class:

public static void main(String arg[]) throws JsonProcessingException {
  Address a = new Address("Jln Koli", "90121", "Vila", "Belgium");
  Person p = new Person("Ali Bin Baba", new Date(), 90.0, 12, a);

  List<Person> persons = new LinkedList<>();
  persons.add(p);
  persons.add(p);

  ObjectMapper mapper = new ObjectMapper(new AvroFactory());
  AvroSchemaGenerator generator = new AvroSchemaGenerator();
  mapper.acceptJsonFormatVisitor(Person.class, generator);
  AvroSchema shema = generator.getGeneratedSchema();
  byte[] avro = mapper.writer(shema).writeValueAsBytes(p);

  System.out.println(avro.toString());
}

This is my Person.java:

@XmlRootElement(name = "Person")
public class Person {
private String name;
private double height;
private int age;
private Date date;
@XmlElement(name = "Address")
private Address address;
    //getters/setters
}

Errors: enter image description here

My Questions:

  1. Currently, I was written code for writing Avro-encoded data by using Jackson 2. But I got this errors. I dont know which part is going wrong. It looks, another data format like JSON, YAML, XML are work fine.
StaxMan
  • 113,358
  • 34
  • 211
  • 239
Auf
  • 473
  • 2
  • 5
  • 9
  • At line you have written code as `List persons = new LinkedList<>();` change it to `List persons = new LinkedList();` I am not sure, but how your code got compiled ? – Mandar Pandit Jun 12 '14 at 05:59
  • Mandar Pandit, it diamond operator for java. Work fine for JDK1.7 . My code doesn't have any problems, just avro part only. – Auf Jun 12 '14 at 06:43
  • 2
    I'm not able to reproduce the error. Which version of Jackson/Avro are running? Can you try 2.4.0? – Alexey Gavrilov Jun 14 '14 at 21:40

1 Answers1

1

So this was reported as

https://github.com/FasterXML/jackson-dataformat-avro/issues/8

and fixed in soon-to-be-released 2.4.1 patch release.

StaxMan
  • 113,358
  • 34
  • 211
  • 239