22
33import com .fasterxml .jackson .annotation .JsonProperty ;
44import com .fasterxml .jackson .databind .JsonMappingException ;
5- import com .fasterxml .jackson .dataformat .avro .annotation .Decimal ;
5+ import com .fasterxml .jackson .dataformat .avro .annotation .AvroDecimal ;
66import com .fasterxml .jackson .dataformat .avro .schema .AvroSchemaGenerator ;
77import org .apache .avro .LogicalTypes ;
88import org .apache .avro .Schema ;
1515public class BigDecimal_schemaCreationTest extends AvroTestBase {
1616 private static final AvroMapper MAPPER = new AvroMapper ();
1717
18- static class BigDecimalWithDecimalAnnotationWrapper {
18+ static class BigDecimalWithAvroDecimalAnnotationWrapper {
1919 @ JsonProperty (required = true ) // field is required to have simpler avro schema
20- @ Decimal (precision = 10 , scale = 2 )
20+ @ AvroDecimal (precision = 10 , scale = 2 )
2121 public final BigDecimal bigDecimalValue ;
2222
23- public BigDecimalWithDecimalAnnotationWrapper (BigDecimal bigDecimalValue ) {
23+ public BigDecimalWithAvroDecimalAnnotationWrapper (BigDecimal bigDecimalValue ) {
2424 this .bigDecimalValue = bigDecimalValue ;
2525 }
2626 }
2727
2828 @ Test
29- public void testSchemaCreation_withLogicalTypesDisabled_onBigDecimalWithDecimalAnnotation () throws JsonMappingException {
29+ public void testSchemaCreation_withLogicalTypesDisabled_onBigDecimalWithAvroDecimalAnnotation () throws JsonMappingException {
3030 // GIVEN
3131 AvroSchemaGenerator gen = new AvroSchemaGenerator ()
3232 .disableLogicalTypes ();
3333
3434 // WHEN
35- MAPPER .acceptJsonFormatVisitor (BigDecimalWithDecimalAnnotationWrapper .class , gen );
36- // actualSchema = MAPPER.schemaFor(BigDecimalWithDecimalAnnotationWrapper .class) would be enough in this case
35+ MAPPER .acceptJsonFormatVisitor (BigDecimalWithAvroDecimalAnnotationWrapper .class , gen );
36+ // actualSchema = MAPPER.schemaFor(BigDecimalWithAvroDecimalAnnotationWrapper .class) would be enough in this case
3737 // because logical types are disabled by default.
3838 final Schema actualSchema = gen .getGeneratedSchema ().getAvroSchema ();
3939
40- System .out .println (BigDecimalWithDecimalAnnotationWrapper .class .getSimpleName () + " schema:" + actualSchema .toString (true ));
40+ System .out .println (BigDecimalWithAvroDecimalAnnotationWrapper .class .getSimpleName () + " schema:" + actualSchema .toString (true ));
4141
4242 // THEN
4343 assertThat (actualSchema .getField ("bigDecimalValue" )).isNotNull ();
@@ -48,16 +48,16 @@ public void testSchemaCreation_withLogicalTypesDisabled_onBigDecimalWithDecimalA
4848 }
4949
5050 @ Test
51- public void testSchemaCreation_withLogicalTypesEnabled_onBigDecimalWithDecimalAnnotation () throws JsonMappingException {
51+ public void testSchemaCreation_withLogicalTypesEnabled_onBigDecimalWithAvroDecimalAnnotation () throws JsonMappingException {
5252 // GIVEN
5353 AvroSchemaGenerator gen = new AvroSchemaGenerator ()
5454 .enableLogicalTypes ();
5555
5656 // WHEN
57- MAPPER .acceptJsonFormatVisitor (BigDecimalWithDecimalAnnotationWrapper .class , gen );
57+ MAPPER .acceptJsonFormatVisitor (BigDecimalWithAvroDecimalAnnotationWrapper .class , gen );
5858 final Schema actualSchema = gen .getGeneratedSchema ().getAvroSchema ();
5959
60- System .out .println (BigDecimalWithDecimalAnnotationWrapper .class .getSimpleName () + " schema:" + actualSchema .toString (true ));
60+ System .out .println (BigDecimalWithAvroDecimalAnnotationWrapper .class .getSimpleName () + " schema:" + actualSchema .toString (true ));
6161
6262 // THEN
6363 assertThat (actualSchema .getField ("bigDecimalValue" )).isNotNull ();
@@ -67,28 +67,28 @@ public void testSchemaCreation_withLogicalTypesEnabled_onBigDecimalWithDecimalAn
6767 assertThat (bigDecimalValue .getProp ("java-class" )).isNull ();
6868 }
6969
70- static class BigDecimalWithDecimalAnnotationToFixedWrapper {
70+ static class BigDecimalWithAvroDecimalAnnotationToFixedWrapper {
7171 @ JsonProperty (required = true ) // field is required to have simpler avro schema
72- @ AvroFixedSize (typeName = "BigDecimalWithDecimalAnnotationToFixedWrapper " , size = 10 )
73- @ Decimal (precision = 6 , scale = 3 )
72+ @ AvroFixedSize (typeName = "BigDecimalWithAvroDecimalAnnotationToFixedWrapper " , size = 10 )
73+ @ AvroDecimal (precision = 6 , scale = 3 )
7474 public final BigDecimal bigDecimalValue ;
7575
76- public BigDecimalWithDecimalAnnotationToFixedWrapper (BigDecimal bigDecimalValue ) {
76+ public BigDecimalWithAvroDecimalAnnotationToFixedWrapper (BigDecimal bigDecimalValue ) {
7777 this .bigDecimalValue = bigDecimalValue ;
7878 }
7979 }
8080
8181 @ Test
82- public void testSchemaCreation_withLogicalTypesEnabled_onBigDecimalWithDecimalAnnotationToFixed () throws JsonMappingException {
82+ public void testSchemaCreation_withLogicalTypesEnabled_onBigDecimalWithAvroDecimalAnnotationToFixed () throws JsonMappingException {
8383 // GIVEN
8484 AvroSchemaGenerator gen = new AvroSchemaGenerator ()
8585 .enableLogicalTypes ();
8686
8787 // WHEN
88- MAPPER .acceptJsonFormatVisitor (BigDecimalWithDecimalAnnotationToFixedWrapper .class , gen );
88+ MAPPER .acceptJsonFormatVisitor (BigDecimalWithAvroDecimalAnnotationToFixedWrapper .class , gen );
8989 final Schema actualSchema = gen .getGeneratedSchema ().getAvroSchema ();
9090
91- System .out .println (BigDecimalWithDecimalAnnotationToFixedWrapper .class .getSimpleName () + " schema:" + actualSchema .toString (true ));
91+ System .out .println (BigDecimalWithAvroDecimalAnnotationToFixedWrapper .class .getSimpleName () + " schema:" + actualSchema .toString (true ));
9292
9393 // THEN
9494 assertThat (actualSchema .getField ("bigDecimalValue" )).isNotNull ();
0 commit comments