Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,31 @@ private ProtobufField _findAndResolve(FieldElement nativeField, String typeStr)
if (nativeMt != null) {
return new ProtobufField(nativeField, resolve(this, nativeMt));
}
return null;
// [dataformats-binary#73] Handle dot-notation references to nested message types
// (e.g. "OuterType.InnerType")
return _findDottedType(nativeField, typeStr);
}

/**
* Try to resolve a dot-notation type reference (e.g. {@code "OuterType.InnerType"})
* by navigating the message type hierarchy declared at this scope level.
*/
private ProtobufField _findDottedType(FieldElement nativeField, String typeStr)
{
int dotIx = typeStr.indexOf('.');
if (dotIx <= 0) {
return null;
}
String outerName = typeStr.substring(0, dotIx);
String innerPath = typeStr.substring(dotIx + 1);
MessageElement outerMsg = _declaredMessageTypes.get(outerName);
if (outerMsg == null) {
return null;
}
// Create a resolver in the context of the outer type and recursively
// resolve the remaining path (handles arbitrary nesting depth)
TypeResolver outerResolver = TypeResolver.construct(this, outerName, outerMsg.nestedElements());
return outerResolver._findAndResolve(nativeField, innerPath);
}

private StringBuilder _knownEnums(StringBuilder sb) {
Expand Down
1 change: 0 additions & 1 deletion protobuf/src/test/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@
opens tools.jackson.dataformat.protobuf.schema;
opens tools.jackson.dataformat.protobuf.testutil;
opens tools.jackson.dataformat.protobuf.testutil.failure;
opens tools.jackson.dataformat.protobuf.tofix;
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
package tools.jackson.dataformat.protobuf.tofix;
package tools.jackson.dataformat.protobuf.schema;

import java.io.StringReader;

import org.junit.jupiter.api.Test;

import tools.jackson.dataformat.protobuf.ProtobufMapper;
import tools.jackson.dataformat.protobuf.ProtobufTestBase;
import tools.jackson.dataformat.protobuf.schema.ProtobufSchema;
import tools.jackson.dataformat.protobuf.testutil.failure.JacksonTestFailureExpected;

import static org.junit.jupiter.api.Assertions.assertNotNull;

public class GenerateNestedType73Test extends ProtobufTestBase
// [dataformats-binary#73]
public class NestedTypeRef73Test extends ProtobufTestBase
{
/*
/**********************************************************
/* Test methods
/**********************************************************
*/

final ProtobufMapper MAPPER = new ProtobufMapper();

// [dataformats-binary#68]
@JacksonTestFailureExpected
// [dataformats-binary#73]: dot-notation reference to a nested message type
@Test
public void testNestedTypes() throws Exception
public void testNestedTypeRefViaRootType() throws Exception
{
final String SCHEMA_STR =
" package mypackage;\n"
Expand Down
5 changes: 5 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ Fawzi Essam (@iifawzi)
* Contributed #591: Change `CBOR` Features defaults for 3.0
(3.0.0)

Kenji Noguchi (@knoguchi)

* Reported #73: (protobuf) Cannot resolve inner types in protoc definitions
(3.1.0)

Andy Wilkinson (@wilkinsona)

* Requested #619: (avro, cbor, ion, smile) Add `isEnabled()` methods for format-specific features
Expand Down
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ implementations)

3.1.0 (not yet released)

#73: (protobuf) Cannot resolve inner types in protoc definitions
(reported by Kenji N)
#649: (cbor, smile) `StreamReadConstraints.maxDocumentLength` not checked
when creating parser with fixed buffer

Expand Down