Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ApacheAvro Maven插件生成UUID字段而不是字符串_Java_Maven_Code Generation_Avro - Fatal编程技术网

Java ApacheAvro Maven插件生成UUID字段而不是字符串

Java ApacheAvro Maven插件生成UUID字段而不是字符串,java,maven,code-generation,avro,Java,Maven,Code Generation,Avro,给定以下Avro模式: { "namespace": "ro.dspr.coreentities", "type": "record", "name": "Organization", "fields": [ { "name": "id", "type": "string", "logicalType": "uuid" }, { "name": "name",

给定以下Avro模式:

{
    "namespace": "ro.dspr.coreentities",
    "type": "record",
    "name": "Organization",
    "fields": [
      {
        "name": "id",
        "type": "string",
        "logicalType": "uuid"
      },
      {
        "name": "name",
        "type": "string"
      },
      {
        "name": "description",
        "type": "string"
      }
    ]
}
运行avro maven插件1.9.0目标模式,我得到:

我希望为组织生成的POJO具有id UUID,而不是字符串(我现在拥有的)

我看到的链接: 我确实看到了,我实际上是想触发,但我无法连接这些点

另外 相关Maven pom零件

<plugin>
  <groupId>org.apache.avro</groupId>
  <artifactId>avro-maven-plugin</artifactId>
  <version>${avro.version}</version>
  <configuration>
    <sourceDirectory>${avro-files-path}</sourceDirectory>
    <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
    <stringType>String</stringType>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>schema</goal>
      </goals>
      <configuration>
        <sourceDirectory>${avro-files-path}</sourceDirectory>
        <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

org.apache.avro
avro-maven插件
${avro.version}
${avro文件路径}
${project.build.directory}/生成的源
一串
模式
${avro文件路径}
${project.build.directory}/生成的源
额外信息 事实上,我试图用Avro给我的卡夫卡信息一个结构。我还使用Confluent模式注册表和Confluent Avro Kafka序列化程序。尽管如此,我认为我只能将id作为字符串,但如果我尝试将消息作为非UUID的内容发送给Kafka,它将在稍后失败。然而,我发现实际上没有约束,我设法将任何字符串发送给卡夫卡。因此,Avro中的“logicalType”根本不强制执行

问题
  • 如何将Organization.class#id生成为UUID
  • 如果不支持Avro,那么解决方法是什么(最好重用org.apache.Avro.Conversions.UUIDConversion)

  • 以下是一个功能示例:

    模式:

    {
      "name": "pk",
      "type": {"type": "string", "logicalType": "uuid"}
    },
    
    Maven配置:

                <plugin>
                    <groupId>org.apache.avro</groupId>
                    <artifactId>avro-maven-plugin</artifactId>
                    <version>1.9.1</version>
                    <executions>
                        <execution>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>schema</goal>
                            </goals>
                            <configuration>
                                <sourceDirectory>${project.basedir}/../avro/schemas/commands</sourceDirectory>
                                <outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory>
                                <!-- TODO Enable this string type once we have 1.10.0 release, or 1.9.2-->
                                <!--<stringType>String</stringType>-->
                                <fieldVisibility>PRIVATE</fieldVisibility>
                                <customConversions>org.apache.avro.Conversions$UUIDConversion</customConversions>
                                <imports>
                                    <import>${project.basedir}/../avro/schemas/common</import>
                                    <import>${project.basedir}/../avro/schemas/commands/account</import>
                                    <import>${project.basedir}/../avro/schemas/commands/rec</import>
                                </imports>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    
    
    org.apache.avro
    avro-maven插件
    1.9.1
    生成源
    模式
    ${project.basedir}/./avro/schemas/commands
    ${project.build.directory}/generated sources/java
    私有的
    org.apache.avro.Conversions$UUIDConversion
    ${project.basedir}/./avro/schemas/common
    ${project.basedir}/./avro/schemas/commands/account
    ${project.basedir}/./avro/schemas/commands/rec
    

    需要注意的重要一点是,在当前版本的插件中,UUIDConversion和String之间存在冲突,因此您需要选择哪个更重要,或者使用1.10.0-SNAPSHOT,该快照已合并修复程序,但尚未发布。

    您是否尝试过“logicalType”:“uuid”,从文档上看,它似乎需要小写。这实际上是我尝试的第一件事,但没有成功。在POJO的模式中,logicalType uuid在那里(它被正确识别,因为您不能在那里放置任何东西,否则它将失败),您找到了一种方法吗?您好。没有,但说实话,从那以后我就没有尝试过。即使没有stringType和CustomConversion,生成的java类仍然希望将
    CharSequence
    作为setter的参数。非常感谢!为了解决uuid问题,我整天都头疼
                <plugin>
                    <groupId>org.apache.avro</groupId>
                    <artifactId>avro-maven-plugin</artifactId>
                    <version>1.9.1</version>
                    <executions>
                        <execution>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>schema</goal>
                            </goals>
                            <configuration>
                                <sourceDirectory>${project.basedir}/../avro/schemas/commands</sourceDirectory>
                                <outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory>
                                <!-- TODO Enable this string type once we have 1.10.0 release, or 1.9.2-->
                                <!--<stringType>String</stringType>-->
                                <fieldVisibility>PRIVATE</fieldVisibility>
                                <customConversions>org.apache.avro.Conversions$UUIDConversion</customConversions>
                                <imports>
                                    <import>${project.basedir}/../avro/schemas/common</import>
                                    <import>${project.basedir}/../avro/schemas/commands/account</import>
                                    <import>${project.basedir}/../avro/schemas/commands/rec</import>
                                </imports>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>