从某些Java对象生成Avro模式 [英] Generate Avro Schema from certain Java Object

查看:336
本文介绍了从某些Java对象生成Avro模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apache Avro提供了紧凑,快速的二进制数据格式,丰富的数据结构用于序列化.但是,它要求用户为需要序列化的对象定义一个模式(JSON).

Apache Avro provides a compact, fast, binary data format, rich data structure for serialization. However, it requires user to define a schema (in JSON) for object which need to be serialized.

在某些情况下,这是不可能的(例如:该Java对象的类具有某些成员,这些成员的类型是外部库中的外部Java类).因此,我想知道是否有一种工具可以从对象的.class文件中获取信息并生成该对象的Avro模式(例如Gson使用对象的.class信息将某些对象转换为JSON字符串).

In some case, this can not be possible (e.g: the class of that Java object has some members whose types are external java classes in external libraries). Hence, I wonder there is a tool can get the information from object's .class file and generate the Avro schema for that object (like Gson use object's .class information to convert certain object to JSON string).

推荐答案

看看获取架构如下:

Schema schema = ReflectData.get().getSchema(T);

有关其他问题,请参见道格的示例,了解工作示例.

See the example from Doug on another question for a working example.

此答案的积分属于Sean Busby.

Credits of this answer belong to Sean Busby.

这篇关于从某些Java对象生成Avro模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆