1

I'm facing a very weird problem when dealing with date fields while serializing and deserializing the data in AVRO format.

We have a JPA entity defined as follows

@Entity
public class Person implements Serializable{
    @Column(name = "DOB")
    @Temporal(TemporalType.DATE)
    protected Date dob;

we read the payload which is in JSON, that can be deserialized to the above entity before persisting the data. After that, if I query the database like

  select * from Persons where dob='01-JAN-2019' -- I get records

But instead of JSON, if it were AVRO, send it over HTTP to the service, where it is read and converted to Entity and persisted, I get status as the record is persisted. However, if I run the same SELECT I do not see data unless I explicitly say

  select * from Persons where to_date(dob)='01-JAN-2019'.

But if I run the same code base locally on my machine, it works like a charm, but the same code deployed to our DIT and other regions, it does not work.

Did anyone face similar issue?

I added a proxy data source and enabled logging for net.ttddyy.dsproxy.support.ProxyDataSource.

Logs are exactly the same when it ran locally and remote.

In the case of JSON

Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JSONDateDeserializer()).create();
JsonReader reader = new JsonReader(is); //where is InputStreamReader(ServletInputStream)
reader.beginArray();
while(reader.hasNext()){

   Person p = gson.fromJson(reader,Person.class);
   repository.save(p); //This works fine
 ..........

JSONDateDeserializer has custom Deserialize logic. 

In the case of AVRO

 AvroMapper avroMapper = new AvroMapper();
 AvroSchema schema = avroMapper.schemaFor(Person.class);
 objectReader = avroMapper.readerFor(Person.class)
       .with(schema);
 MappingIterator<Person> mi = objectReader.readValues(is); //read from servletInputStream
 mi.forEachRemaining(p->repository.save(p)); //Data is saved, but date field is behaving differently

I think, there should be a way to register a custom date serializer and Deserializer just like JsonDateDeserializer.

DBreaker
  • 319
  • 1
  • 4
  • 24

0 Answers0