Skip to content

Commit 48cb91c

Browse files
authored
Schema Registry: Change Encoder to Serializer (Azure#27662)
* Adding explicit dependency on azure-core. * Updating class name from Encoder -> Serializer. * Rename encode/decode to deserialize/serialize. * Rename playback files. * Fix README file snippets. * Fix CHANGELOG entries.
1 parent 6904105 commit 48cb91c

14 files changed

+139
-130
lines changed

sdk/schemaregistry/azure-data-schemaregistry-apacheavro/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
### Breaking Changes
88

9+
- Changed `SchemaRegistryApacheAvroEncoder` to `SchemaRegistryApacheAvroSerializer`.
10+
- Changed `decodeMessageData` and `decodeMessageDataAsync` to `deserializeMessageData` and `deserializeMessageDataAsync`.
11+
- Changed `encodeMessageData` and `encodeMessageDataAsync` to `serializeMessageData` and `serializeMessageDataAsync`.
12+
913
### Bugs Fixed
1014

1115
### Other Changes
@@ -14,7 +18,7 @@
1418

1519
### Features Added
1620

17-
- Changed `SchemaRegistryApacheAvroEncoder` to deserialize `MessageWithMetadata` rather than tied to a binary format
21+
- Changed `SchemaRegistryApacheAvroEncoder` to deserialize `MessageWithMetadata` rather than tied to a binary format
1822
with preamble. Backwards compatibility with preamble format supported for this release. See issue #26449.
1923

2024
### Breaking Changes

sdk/schemaregistry/azure-data-schemaregistry-apacheavro/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBu
7272

7373
#### Create `SchemaRegistryAvroSerializer` through the builder
7474

75-
```java readme-sample-createSchemaRegistryAvroEncoder
76-
SchemaRegistryApacheAvroEncoder encoder = new SchemaRegistryApacheAvroEncoderBuilder()
75+
```java readme-sample-createSchemaRegistryAvroSerializer
76+
SchemaRegistryApacheAvroSerializer serializer = new SchemaRegistryApacheAvroSerializerBuilder()
7777
.schemaRegistryAsyncClient(schemaRegistryAsyncClient)
7878
.schemaGroup("{schema-group}")
79-
.buildEncoder();
79+
.buildSerializer();
8080
```
8181

8282
## Key concepts
@@ -105,13 +105,13 @@ The serializer in this library creates messages in a wire format. The format is
105105
### Serialize
106106
Serialize a strongly-typed object into Schema Registry-compatible avro payload.
107107

108-
```java readme-sample-encodeSample
108+
```java readme-sample-serializeSample
109109
PlayingCard playingCard = new PlayingCard();
110110
playingCard.setPlayingCardSuit(PlayingCardSuit.SPADES);
111111
playingCard.setIsFaceCard(false);
112112
playingCard.setCardValue(5);
113113

114-
MessageWithMetadata message = encoder.encodeMessageData(playingCard,
114+
MessageWithMetadata message = serializer.serializeMessageData(playingCard,
115115
TypeReference.createInstance(MessageWithMetadata.class));
116116
```
117117

@@ -121,10 +121,10 @@ The avro type `PlayingCard` is available in samples package
121121
### Deserialize
122122
Deserialize a Schema Registry-compatible avro payload into a strongly-type object.
123123

124-
```java readme-sample-decodeSample
125-
SchemaRegistryApacheAvroEncoder encoder = createAvroSchemaRegistryEncoder();
124+
```java readme-sample-deserializeSample
125+
SchemaRegistryApacheAvroSerializer serializer = createAvroSchemaRegistrySerializer();
126126
MessageWithMetadata message = getSchemaRegistryAvroMessage();
127-
PlayingCard playingCard = encoder.decodeMessageData(message, TypeReference.createInstance(PlayingCard.class));
127+
PlayingCard playingCard = serializer.deserializeMessageData(message, TypeReference.createInstance(PlayingCard.class));
128128
```
129129

130130
## Troubleshooting

sdk/schemaregistry/azure-data-schemaregistry-apacheavro/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
</properties>
4545

4646
<dependencies>
47+
<dependency>
48+
<groupId>com.azure</groupId>
49+
<artifactId>azure-core</artifactId>
50+
<version>1.26.0</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
51+
</dependency>
4752
<dependency>
4853
<groupId>com.azure</groupId>
4954
<artifactId>azure-core-experimental</artifactId>
Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
/**
2929
* Schema Registry-based serializer implementation for Avro data format using Apache Avro.
3030
*/
31-
public final class SchemaRegistryApacheAvroEncoder {
31+
public final class SchemaRegistryApacheAvroSerializer {
3232
static final String AVRO_MIME_TYPE = "avro/binary";
3333
static final byte[] RECORD_FORMAT_INDICATOR = new byte[]{0x00, 0x00, 0x00, 0x00};
3434
static final int RECORD_FORMAT_INDICATOR_SIZE = RECORD_FORMAT_INDICATOR.length;
3535
static final int SCHEMA_ID_SIZE = 32;
3636

37-
private final ClientLogger logger = new ClientLogger(SchemaRegistryApacheAvroEncoder.class);
37+
private final ClientLogger logger = new ClientLogger(SchemaRegistryApacheAvroSerializer.class);
3838
private final SchemaRegistryAsyncClient schemaRegistryClient;
3939
private final AvroSerializer avroSerializer;
4040
private final SerializerOptions serializerOptions;
@@ -46,7 +46,7 @@ public final class SchemaRegistryApacheAvroEncoder {
4646
* @param avroSerializer Serializer implemented using Apache Avro.
4747
* @param serializerOptions Options to configure the serializer with.
4848
*/
49-
SchemaRegistryApacheAvroEncoder(SchemaRegistryAsyncClient schemaRegistryClient,
49+
SchemaRegistryApacheAvroSerializer(SchemaRegistryAsyncClient schemaRegistryClient,
5050
AvroSerializer avroSerializer, SerializerOptions serializerOptions) {
5151
this.schemaRegistryClient = Objects.requireNonNull(schemaRegistryClient,
5252
"'schemaRegistryClient' cannot be null.");
@@ -56,84 +56,84 @@ public final class SchemaRegistryApacheAvroEncoder {
5656
}
5757

5858
/**
59-
* Encodes an object into a message.
59+
* Serializes an object into a message.
6060
*
61-
* @param object Object to encode.
61+
* @param object Object to serialize.
6262
* @param typeReference Type of message to create.
6363
* @param <T> Concrete type of {@link MessageWithMetadata}.
6464
*
65-
* @return The message encoded or {@code null} if the message could not be encoded.
65+
* @return The message encoded or {@code null} if the message could not be serialized.
6666
*
6767
* @throws IllegalArgumentException if {@code messageFactory} is null and type {@code T} does not have a no
68-
* argument constructor. Or if the schema could not ve fetched from {@code T}.
68+
* argument constructor. Or if the schema could not be fetched from {@code T}.
6969
* @throws RuntimeException if an instance of {@code T} could not be instantiated. Or there was a problem
7070
* encoding the object.
7171
* @throws NullPointerException if the {@code object} is null or {@code typeReference} is null.
7272
*/
73-
public <T extends MessageWithMetadata> T encodeMessageData(Object object, TypeReference<T> typeReference) {
74-
return encodeMessageDataAsync(object, typeReference).block();
73+
public <T extends MessageWithMetadata> T serializeMessageData(Object object, TypeReference<T> typeReference) {
74+
return serializeMessageDataAsync(object, typeReference).block();
7575
}
7676

7777
/**
78-
* Encodes an object into a message.
78+
* Serializes an object into a message.
7979
*
80-
* @param object Object to encode.
80+
* @param object Object to serialize.
8181
* @param typeReference Type of message to create.
8282
* @param messageFactory Factory to create an instance given the serialized Avro.
8383
* @param <T> Concrete type of {@link MessageWithMetadata}.
8484
*
85-
* @return The message encoded or {@code null} if the message could not be encoded.
85+
* @return The message encoded or {@code null} if the message could not be serialized.
8686
*
8787
* @throws IllegalArgumentException if {@code messageFactory} is null and type {@code T} does not have a no
88-
* argument constructor. Or if the schema could not ve fetched from {@code T}.
88+
* argument constructor. Or if the schema could not be fetched from {@code T}.
8989
* @throws RuntimeException if an instance of {@code T} could not be instantiated. Or there was a problem
9090
* encoding the object.
9191
* @throws NullPointerException if the {@code object} is null or {@code typeReference} is null.
9292
*/
93-
public <T extends MessageWithMetadata> T encodeMessageData(Object object, TypeReference<T> typeReference,
93+
public <T extends MessageWithMetadata> T serializeMessageData(Object object, TypeReference<T> typeReference,
9494
Function<BinaryData, T> messageFactory) {
95-
return encodeMessageDataAsync(object, typeReference, messageFactory).block();
95+
return serializeMessageDataAsync(object, typeReference, messageFactory).block();
9696
}
9797

9898
/**
99-
* Encodes an object into a message.
99+
* Serializes an object into a message.
100100
*
101-
* @param object Object to encode.
101+
* @param object Object to serialize.
102102
* @param typeReference Type of message to create.
103103
* @param <T> Concrete type of {@link MessageWithMetadata}.
104104
*
105-
* @return A Mono that completes with the encoded message.
105+
* @return A Mono that completes with the serialized message.
106106
*
107107
* @throws IllegalArgumentException if {@code messageFactory} is null and type {@code T} does not have a no
108-
* argument constructor. Or if the schema could not ve fetched from {@code T}.
108+
* argument constructor. Or if the schema could not be fetched from {@code T}.
109109
* @throws RuntimeException if an instance of {@code T} could not be instantiated. Or there was a problem
110110
* encoding the object.
111111
* @throws NullPointerException if the {@code object} is null or {@code typeReference} is null.
112112
*/
113-
public <T extends MessageWithMetadata> Mono<T> encodeMessageDataAsync(Object object,
113+
public <T extends MessageWithMetadata> Mono<T> serializeMessageDataAsync(Object object,
114114
TypeReference<T> typeReference) {
115115

116-
return encodeMessageDataAsync(object, typeReference, null);
116+
return serializeMessageDataAsync(object, typeReference, null);
117117
}
118118

119119
/**
120-
* Encodes an object into a message.
120+
* Serializes an object into a message.
121121
*
122-
* @param object Object to encode.
122+
* @param object Object to serialize.
123123
* @param typeReference Type of message to create.
124124
* @param messageFactory Factory to create an instance given the serialized Avro. If null is passed in, then the
125125
* no argument constructor will be used.
126126
* @param <T> Concrete type of {@link MessageWithMetadata}.
127127
*
128-
* @return A Mono that completes with the encoded message.
128+
* @return A Mono that completes with the serialized message.
129129
*
130130
* @throws IllegalArgumentException if {@code messageFactory} is null and type {@code T} does not have a no
131-
* argument constructor. Or if the schema could not ve fetched from {@code T}.
131+
* argument constructor. Or if the schema could not be fetched from {@code T}.
132132
* @throws RuntimeException if an instance of {@code T} could not be instantiated. Or there was a problem
133133
* encoding the object.
134134
* @throws NullPointerException if the {@code object} is null or {@code typeReference} is null.
135135
*/
136-
public <T extends MessageWithMetadata> Mono<T> encodeMessageDataAsync(Object object,
136+
public <T extends MessageWithMetadata> Mono<T> serializeMessageDataAsync(Object object,
137137
TypeReference<T> typeReference, Function<BinaryData, T> messageFactory) {
138138

139139
if (object == null) {
@@ -189,33 +189,33 @@ public <T extends MessageWithMetadata> Mono<T> encodeMessageDataAsync(Object obj
189189
}
190190

191191
/**
192-
* Decodes a message into its object.
192+
* Deserializes a message into its object.
193193
*
194-
* @param message Object to encode.
195-
* @param typeReference Message to encode to.
194+
* @param message Object to deserialize.
195+
* @param typeReference Message type to deserialize to.
196196
* @param <T> Concrete type of {@link MessageWithMetadata}.
197197
*
198-
* @return The message encoded.
198+
* @return The message deserialized.
199199
*
200200
* @throws NullPointerException if {@code message} or {@code typeReference} is null.
201201
*/
202-
public <T> T decodeMessageData(MessageWithMetadata message, TypeReference<T> typeReference) {
203-
return decodeMessageDataAsync(message, typeReference).block();
202+
public <T> T deserializeMessageData(MessageWithMetadata message, TypeReference<T> typeReference) {
203+
return deserializeMessageDataAsync(message, typeReference).block();
204204
}
205205

206206
/**
207-
* Decodes a message into its object.
207+
* Deserializes a message into its object.
208208
*
209-
* @param message Object to encode.
210-
* @param typeReference Message to encode to.
209+
* @param message Object to deserialize.
210+
* @param typeReference Message to deserialize to.
211211
* @param <T> Concrete type of {@link MessageWithMetadata}.
212212
*
213213
* @return A Mono that completes when the message encoded. If {@code message.getBodyAsBinaryData()} is null or
214214
* empty, then an empty Mono is returned.
215215
*
216216
* @throws NullPointerException if {@code message} or {@code typeReference} is null.
217217
*/
218-
public <T> Mono<T> decodeMessageDataAsync(MessageWithMetadata message, TypeReference<T> typeReference) {
218+
public <T> Mono<T> deserializeMessageDataAsync(MessageWithMetadata message, TypeReference<T> typeReference) {
219219
if (message == null) {
220220
return monoError(logger, new NullPointerException("'message' cannot be null."));
221221
} else if (typeReference == null) {
@@ -282,10 +282,10 @@ public <T> Mono<T> decodeMessageDataAsync(MessageWithMetadata message, TypeRefer
282282
contents.reset();
283283
}
284284

285-
return decodeMessageDataAsync(schemaId, contents, typeReference);
285+
return deserializeMessageDataAsync(schemaId, contents, typeReference);
286286
}
287287

288-
private <T> Mono<T> decodeMessageDataAsync(String schemaId, ByteBuffer buffer, TypeReference<T> typeReference) {
288+
private <T> Mono<T> deserializeMessageDataAsync(String schemaId, ByteBuffer buffer, TypeReference<T> typeReference) {
289289
return this.schemaRegistryClient.getSchema(schemaId)
290290
.handle((registryObject, sink) -> {
291291
final byte[] payloadSchema = registryObject.getDefinition().getBytes(StandardCharsets.UTF_8);
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
import java.util.Objects;
1616

1717
/**
18-
* The builder implementation for building {@link SchemaRegistryApacheAvroEncoder}.
18+
* The builder implementation for building {@link SchemaRegistryApacheAvroSerializer}.
1919
*
20-
* @see SchemaRegistryApacheAvroEncoder
20+
* @see SchemaRegistryApacheAvroSerializer
2121
*/
22-
public final class SchemaRegistryApacheAvroEncoderBuilder {
22+
public final class SchemaRegistryApacheAvroSerializerBuilder {
2323
private static final boolean AVRO_SPECIFIC_READER_DEFAULT = false;
2424
private static final int MAX_CACHE_SIZE = 128;
2525

26-
private final ClientLogger logger = new ClientLogger(SchemaRegistryApacheAvroEncoderBuilder.class);
26+
private final ClientLogger logger = new ClientLogger(SchemaRegistryApacheAvroSerializerBuilder.class);
2727
private Boolean autoRegisterSchemas;
2828
private Boolean avroSpecificReader;
2929
private SchemaRegistryAsyncClient schemaRegistryAsyncClient;
@@ -32,7 +32,7 @@ public final class SchemaRegistryApacheAvroEncoderBuilder {
3232
/**
3333
* Instantiates instance of Builder class. Supplies client defaults.
3434
*/
35-
public SchemaRegistryApacheAvroEncoderBuilder() {
35+
public SchemaRegistryApacheAvroSerializerBuilder() {
3636
this.autoRegisterSchemas = false;
3737
this.avroSpecificReader = false;
3838
}
@@ -46,9 +46,9 @@ public SchemaRegistryApacheAvroEncoderBuilder() {
4646
*
4747
* @param schemaGroup Azure Schema Registry schema group
4848
*
49-
* @return updated {@link SchemaRegistryApacheAvroEncoderBuilder} instance
49+
* @return updated {@link SchemaRegistryApacheAvroSerializerBuilder} instance
5050
*/
51-
public SchemaRegistryApacheAvroEncoderBuilder schemaGroup(String schemaGroup) {
51+
public SchemaRegistryApacheAvroSerializerBuilder schemaGroup(String schemaGroup) {
5252
this.schemaGroup = schemaGroup;
5353
return this;
5454
}
@@ -64,9 +64,9 @@ public SchemaRegistryApacheAvroEncoderBuilder schemaGroup(String schemaGroup) {
6464
*
6565
* @param autoRegisterSchemas flag for schema auto-registration
6666
*
67-
* @return updated {@link SchemaRegistryApacheAvroEncoderBuilder} instance
67+
* @return updated {@link SchemaRegistryApacheAvroSerializerBuilder} instance
6868
*/
69-
public SchemaRegistryApacheAvroEncoderBuilder autoRegisterSchema(boolean autoRegisterSchemas) {
69+
public SchemaRegistryApacheAvroSerializerBuilder autoRegisterSchema(boolean autoRegisterSchemas) {
7070
this.autoRegisterSchemas = autoRegisterSchemas;
7171
return this;
7272
}
@@ -78,9 +78,9 @@ public SchemaRegistryApacheAvroEncoderBuilder autoRegisterSchema(boolean autoReg
7878
* @param avroSpecificReader {@code true} to deserialize into {@link SpecificRecord} via {@link
7979
* SpecificDatumReader}; {@code false} otherwise.
8080
*
81-
* @return updated {@link SchemaRegistryApacheAvroEncoderBuilder} instance.
81+
* @return updated {@link SchemaRegistryApacheAvroSerializerBuilder} instance.
8282
*/
83-
public SchemaRegistryApacheAvroEncoderBuilder avroSpecificReader(boolean avroSpecificReader) {
83+
public SchemaRegistryApacheAvroSerializerBuilder avroSpecificReader(boolean avroSpecificReader) {
8484
this.avroSpecificReader = avroSpecificReader;
8585
return this;
8686
}
@@ -90,9 +90,9 @@ public SchemaRegistryApacheAvroEncoderBuilder avroSpecificReader(boolean avroSpe
9090
*
9191
* @param schemaRegistryAsyncClient The {@link SchemaRegistryAsyncClient}.
9292
*
93-
* @return updated {@link SchemaRegistryApacheAvroEncoderBuilder} instance.
93+
* @return updated {@link SchemaRegistryApacheAvroSerializerBuilder} instance.
9494
*/
95-
public SchemaRegistryApacheAvroEncoderBuilder schemaRegistryAsyncClient(
95+
public SchemaRegistryApacheAvroSerializerBuilder schemaRegistryAsyncClient(
9696
SchemaRegistryAsyncClient schemaRegistryAsyncClient) {
9797
this.schemaRegistryAsyncClient = schemaRegistryAsyncClient;
9898
return this;
@@ -101,13 +101,13 @@ public SchemaRegistryApacheAvroEncoderBuilder schemaRegistryAsyncClient(
101101
/**
102102
* Creates a new instance of Schema Registry serializer.
103103
*
104-
* @return A new instance of {@link SchemaRegistryApacheAvroEncoder}.
104+
* @return A new instance of {@link SchemaRegistryApacheAvroSerializer}.
105105
*
106106
* @throws NullPointerException if {@link #schemaRegistryAsyncClient(SchemaRegistryAsyncClient)} is {@code null}
107107
* @throws IllegalStateException if {@link #autoRegisterSchema(boolean)} is {@code true} but {@link
108108
* #schemaGroup(String) schemaGroup} is {@code null}.
109109
*/
110-
public SchemaRegistryApacheAvroEncoder buildEncoder() {
110+
public SchemaRegistryApacheAvroSerializer buildSerializer() {
111111
final boolean isAutoRegister = autoRegisterSchemas != null && autoRegisterSchemas;
112112

113113
if (Objects.isNull(schemaRegistryAsyncClient)) {
@@ -126,6 +126,6 @@ public SchemaRegistryApacheAvroEncoder buildEncoder() {
126126
EncoderFactory.get(), DecoderFactory.get());
127127
final SerializerOptions options = new SerializerOptions(schemaGroup, isAutoRegister, MAX_CACHE_SIZE);
128128

129-
return new SchemaRegistryApacheAvroEncoder(schemaRegistryAsyncClient, codec, options);
129+
return new SchemaRegistryApacheAvroSerializer(schemaRegistryAsyncClient, codec, options);
130130
}
131131
}

sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ This project welcomes contributions and suggestions. See [Contributing][sdk_read
4040
[sdk_readme_troubleshooting]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/README.md#troubleshooting
4141
[sdk_readme_next_steps]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/README.md#next-steps
4242
[sdk_readme_contributing]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/README.md#contributing
43-
[sample_avro_serialization]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroEncoderSample.java
43+
[sample_avro_serialization]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryApacheAvroSerializerSample.java
4444
[sample_avro_deserialization]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/schemaregistry/azure-data-schemaregistry-apacheavro/src/samples/java/com/azure/data/schemaregistry/apacheavro/SchemaRegistryAvroDeserializationSample.java
4545

4646
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%schemaregistry%2Fazure-data-schemaregistry-apacheavro%2Fsrc%2Fsamples%2README.png)

0 commit comments

Comments
 (0)