Skip to content

Commit

Permalink
Unable to decode BigDecimal via ByteBuffer #654
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Dec 17, 2021
1 parent f1ffe6e commit ed0e6cd
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.sksamuel.avro4s

import java.nio.ByteBuffer

import com.sksamuel.avro4s.BigDecimals.BigDecimalConversion
import org.apache.avro.LogicalTypes.Decimal
import org.apache.avro.generic.GenericFixed
import org.apache.avro.{Conversions, Schema, SchemaBuilder}

import java.nio.ByteBuffer
import scala.math.BigDecimal.RoundingMode
import scala.math.BigDecimal.RoundingMode.RoundingMode

Expand Down Expand Up @@ -35,8 +34,10 @@ trait BigDecimalDecoders {

def decode(value: Any): BigDecimal = value match {
case bb: ByteBuffer => converter.fromBytes(bb, schema, decimal)
case f: GenericFixed => converter.fromFixed(f, schema, decimal)
case a: Array[Byte] => converter.fromBytes(ByteBuffer.wrap(a), schema, decimal)
case _ =>
throw new Avro4sDecodingException(s"Unable to decode '$value' to BigDecimal via ByteBuffer", value, this)
throw new Avro4sDecodingException(s"Unable to decode '$value:${value.getClass}' to BigDecimal for schema type BYTES", value, this)
}
}

Expand All @@ -53,7 +54,7 @@ trait BigDecimalDecoders {
def decode(value: Any): BigDecimal = value match {
case f: GenericFixed => converter.fromFixed(f, schema, decimal)
case _ =>
throw new Avro4sDecodingException(s"Unable to decode $value to BigDecimal via GenericFixed", value, this)
throw new Avro4sDecodingException(s"Schema specifies Fixed but value is '$value:${value.getClass}", value, this)
}
}
}
Expand Down

0 comments on commit ed0e6cd

Please sign in to comment.