For example, in org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse.java , the method parse(String schemaIdl) use Schema schema = new Schema.Parser().parse(schemaIdl); to parse schemaIdl, it should adapt to all kind of schema.
private List<Field> parse(String schemaIdl) {
Schema schema = new Schema.Parser().parse(schemaIdl);
return schema.getFields().stream().map(field -> {
String type = field.schema().getType().getName();
// ["null", "double"] represent this field is nullable
if (field.schema().isUnion() && field.schema().getTypes().size() == 2) {
type = field.schema().getTypes().get(1).getName();
}
String defaultVal = field.hasDefaultValue() ? field.defaultVal().toString() : "null";
return Field.builder()
.pos(field.pos())
.name(field.name())
.type(type)
.comment(field.doc())
.isNullable(field.schema().isNullable())
.defaultValue(defaultVal)
.sortType(field.order().name())
.extra("")
.build();
}).collect(Collectors.toList());
}
For example, in
org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse.java
, the methodparse(String schemaIdl)
useSchema schema = new Schema.Parser().parse(schemaIdl);
to parse schemaIdl, it should adapt to all kind of schema.