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

Convert LogicalType BigDecimal to Json #48

Open
gkalogiros-nutmeg opened this issue Jun 4, 2020 · 1 comment
Open

Convert LogicalType BigDecimal to Json #48

gkalogiros-nutmeg opened this issue Jun 4, 2020 · 1 comment

Comments

@gkalogiros-nutmeg
Copy link

gkalogiros-nutmeg commented Jun 4, 2020

Hi all,

First of all thank you for the amazing work you have put in, in this library!

I would like some help with the following problem:

As seen below, I am working on a requirement about exposing some data using the Avro serialization format over Rest:

...
final GenericRecord value = stateStoreQuery.get(key);
final byte[] valueBytes = new JsonAvroConverter().convertToJson(value);
final String response = new String(valueBytes);
return ResponseEntity.ok(response);

Almost all data types are getting converted correctly but decimals. I am assuming this is related to the fact that my Avro POJO uses BigDecimals to represent decimal numbers. I know that this is a logical type in Avro rather than a primitive.

For example the number 0.6060 initialized as new BigDecimal("0.6060") comes back as �¬.

What I am trying to detect unsuccessfully so far is whether the cause of the problem is:

  • The default instance of ObjectMapper used in JsonGenericRecordReader and it doesn't support the conversion from BigDecimals to Strings.
  • The fact that the library does not support Logical types which I doubt as it uses the GenericDatumWriter under the hood.
  • I explicitly need to load any logical types given that BigDecimals are encoded as Avro BYTES.

Any help will be much appreciated!

Thanks in advance!

@adityaabhas
Copy link

Hi all,

First of all thank you for the amazing work you have put in, in this library!

I would like some help with the following problem:

As seen below, I am working on a requirement about exposing some data using the Avro serialization format over Rest:

...
final GenericRecord value = stateStoreQuery.get(key);
final byte[] valueBytes = new JsonAvroConverter().convertToJson(value);
final String response = new String(valueBytes);
return ResponseEntity.ok(response);

Almost all data types are getting converted correctly but decimals. I am assuming this is related to the fact that my Avro POJO uses BigDecimals to represent decimal numbers. I know that this is a logical type in Avro rather than a primitive.

For example the number 0.6060 initialized as new BigDecimal("0.6060") comes back as �¬.

What I am trying to detect unsuccessfully so far is whether the cause of the problem is:

  • The default instance of ObjectMapper used in JsonGenericRecordReader and it doesn't support the conversion from BigDecimals to Strings.
  • The fact that the library does not support Logical types which I doubt as it uses the GenericDatumWriter under the hood.
  • I explicitly need to load any logical types given that BigDecimals are encoded as Avro BYTES.

Any help will be much appreciated!

Thanks in advance!

Hello Georgios, I also need BigDecimal logical type support. Were you able to progress on this?

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

No branches or pull requests

2 participants