Skip to content

Commit 00bcdc5

Browse files
committed
@decimal annotation renamed to @AvroDecinal
1 parent 0e9f562 commit 00bcdc5

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/annotation/Decimal.java renamed to avro/src/main/java/com/fasterxml/jackson/dataformat/avro/annotation/AvroDecimal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
@Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD})
2222
@Retention(RetentionPolicy.RUNTIME)
23-
public @interface Decimal {
23+
public @interface AvroDecimal {
2424

2525
/**
2626
* Maximum precision of decimals stored in this type.

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/schema/RecordVisitor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import com.fasterxml.jackson.databind.jsontype.NamedType;
1717
import com.fasterxml.jackson.databind.ser.BeanPropertyWriter;
1818
import com.fasterxml.jackson.dataformat.avro.AvroFixedSize;
19-
import com.fasterxml.jackson.dataformat.avro.annotation.Decimal;
19+
import com.fasterxml.jackson.dataformat.avro.annotation.AvroDecimal;
2020
import com.fasterxml.jackson.dataformat.avro.ser.CustomEncodingSerializer;
2121

2222
public class RecordVisitor
@@ -155,12 +155,12 @@ protected Schema.Field schemaFieldForWriter(BeanProperty prop, boolean optional)
155155
writerSchema = Schema.createFixed(fixedSize.typeName(), null, fixedSize.typeNamespace(), fixedSize.size());
156156
}
157157
if (_visitorWrapper.isLogicalTypesEnabled()) {
158-
Decimal decimal = prop.getAnnotation(Decimal.class);
159-
if (decimal != null) {
158+
AvroDecimal avroDecimal = prop.getAnnotation(AvroDecimal.class);
159+
if (avroDecimal != null) {
160160
if (writerSchema == null) {
161161
writerSchema = Schema.create(Type.BYTES);
162162
}
163-
writerSchema = LogicalTypes.decimal(decimal.precision(), decimal.scale())
163+
writerSchema = LogicalTypes.decimal(avroDecimal.precision(), avroDecimal.scale())
164164
.addToSchema(writerSchema);
165165
}
166166
}

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/BigDecimal_schemaCreationTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import com.fasterxml.jackson.databind.JsonMappingException;
5-
import com.fasterxml.jackson.dataformat.avro.annotation.Decimal;
5+
import com.fasterxml.jackson.dataformat.avro.annotation.AvroDecimal;
66
import com.fasterxml.jackson.dataformat.avro.schema.AvroSchemaGenerator;
77
import org.apache.avro.LogicalTypes;
88
import org.apache.avro.Schema;
@@ -15,29 +15,29 @@
1515
public 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

Comments
 (0)