Skip to content

Commit 4cb96e0

Browse files
committed
bit more cleanup, to allow passing of untyped protoc reading ObjectMapper
1 parent 3888345 commit 4cb96e0

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/schema/DescriptorLoader.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.Reader;
77
import java.net.URL;
88

9+
import com.fasterxml.jackson.databind.ObjectMapper;
910
import com.fasterxml.jackson.databind.ObjectReader;
1011
import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper;
1112

@@ -24,15 +25,30 @@ public class DescriptorLoader
2425
*/
2526
protected final ObjectReader _reader;
2627

28+
/**
29+
* @param reader {@link ObjectReader} that is able to read protobuf input
30+
* (that is, must have been created from {@link ProtobufMapper}, or regular
31+
* mapper with {@link com.fasterxml.jackson.dataformat.protobuf.ProtobufFactory}),
32+
* and has been configured with `protoc` definition of `descriptor.proro`
33+
*/
2734
public DescriptorLoader(ObjectReader reader) {
2835
_reader = reader;
2936
}
3037

3138
public static DescriptorLoader construct(ProtobufMapper mapper) throws IOException
39+
{
40+
return construct(mapper, mapper.schemaLoader());
41+
}
42+
43+
/**
44+
* @param mapper {@link ObjectMapper} that can reader protoc content.
45+
*/
46+
public static DescriptorLoader construct(ObjectMapper mapper,
47+
ProtobufSchemaLoader schemaLoader) throws IOException
3248
{
3349
ProtobufSchema schema;
3450
try (InputStream in = DescriptorLoader.class.getResourceAsStream(DESCRIPTOR_PROTO)) {
35-
schema = mapper.schemaLoader().load(in, "FileDescriptorSet");
51+
schema = schemaLoader.load(in, "FileDescriptorSet");
3652
}
3753
return new DescriptorLoader(mapper.readerFor(FileDescriptorSet.class)
3854
.with(schema));

0 commit comments

Comments
 (0)