JavaPythonTech blog contains various tools and skills for a developer. Java/Python Best Practices, Tools, Examples, Programming interview questions.

How to make files generated from avro schema file to have String fields instead of Charset fields



Introduction:

Avro is a widely used data serialization system that allows for efficient data exchange between systems and programming languages. When working with Avro, you might encounter scenarios where you need to convert specific fields to string format in the files generated from Avro schemas. In this blog post, we will explore the process of making fields to string in Avro schema-generated files, enabling you to handle data transformations effectively.

Add the below plugin in the project's pom.xml : 

<build>
        <plugins>
             <plugin>
                <groupId>org.apache.avro</groupId>
                <artifactId>avro-maven-plugin</artifactId>
                <version>${avro.version}</version>
                <executions>
                    <execution>
                        <id>schemas</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>schema</goal>
                        </goals>
                        <configuration>
                            <stringType>String</stringType>
                            <imports>
                                <import>${project.basedir}/src/main/avro/example.avsc</import>
                            </imports>
                            <sourceDirectory>src/main/avro</sourceDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
</build>

Notice the configuration <stringType> in bold.

The above configuration will make the generated java files to have fields as String instead of charset.

Hope this helps! Happy coding!
Share:

No comments:

Post a Comment

Announcements

Will be posting twice a week on latest java libraries/frameworks which a developer needs to know in 2019.
Also will add the common errors and resolutions for the same.

Please feel free to comment if you need anything specific.

Recent Posts

Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Contributors

Pages