Skip to content

Commit cf7d5ea

Browse files
committed
Work on tackling #68, not yet fully fixed
1 parent 643981d commit cf7d5ea

File tree

6 files changed

+79
-31
lines changed

6 files changed

+79
-31
lines changed

protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/schemagen/EnumElementVisitor.java

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public EnumElementVisitor(SerializerProvider provider, JavaType type,
2525
_builder = EnumElement.builder();
2626
_builder.name(type.getRawClass().getSimpleName());
2727
_builder.documentation("Enum for " + type.toCanonical());
28-
29-
definedTypeElementBuilders.addTypeElement(type, this, isNested);
3028
}
3129

3230
@Override

protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/schemagen/MessageElementVisitor.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,23 @@ public TypeElement build() {
5151

5252
@Override
5353
public void property(BeanProperty writer) throws JsonMappingException {
54-
FieldElement fElement = buildFieldElement(writer, Label.REQUIRED);
55-
_builder.addField(fElement);
54+
_builder.addField(buildFieldElement(writer, Label.REQUIRED));
5655
}
5756

5857
@Override
59-
public void property(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) { }
58+
public void property(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) {
59+
throw new UnsupportedOperationException();
60+
}
6061

6162
@Override
6263
public void optionalProperty(BeanProperty writer) throws JsonMappingException {
63-
FieldElement fElement = buildFieldElement(writer, Label.OPTIONAL);
64-
_builder.addField(fElement);
64+
_builder.addField(buildFieldElement(writer, Label.OPTIONAL));
6565
}
6666

6767
@Override
68-
public void optionalProperty(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) { }
68+
public void optionalProperty(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) {
69+
throw new UnsupportedOperationException();
70+
}
6971

7072
protected FieldElement buildFieldElement(BeanProperty writer, Label label) throws JsonMappingException
7173
{

protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf/schemagen/ProtoBufSchemaVisitor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public JsonStringFormatVisitor expectStringFormat(JavaType type) {
100100

101101
EnumElementVisitor visitor = new EnumElementVisitor(_provider, type, _definedTypeElementBuilders, _isNested);
102102
_builder = visitor;
103+
_definedTypeElementBuilders.addTypeElement(type, visitor, _isNested);
103104
return visitor;
104105
}
105106

@@ -141,5 +142,4 @@ protected <T> T _throwUnsupported() {
141142
protected <T> T _throwUnsupported(String msg) {
142143
throw new UnsupportedOperationException(msg);
143144
}
144-
145145
}

protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/ReadComplexPojoTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public PojoWithArrays(boolean[] b,
4040
*/
4141

4242
final ProtobufMapper MAPPER = new ProtobufMapper();
43-
43+
4444
public void testMediaItemSimple() throws Exception
4545
{
4646
_testMediaItem(false);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.fasterxml.jackson.dataformat.protobuf.failing;
2+
3+
import java.util.UUID;
4+
5+
import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper;
6+
import com.fasterxml.jackson.dataformat.protobuf.ProtobufTestBase;
7+
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
8+
9+
public class GenerateSchema68Test extends ProtobufTestBase
10+
{
11+
static class UUIDBean
12+
{
13+
public UUID messageId;
14+
}
15+
16+
static class ShortBean
17+
{
18+
public short version;
19+
}
20+
21+
/*
22+
/**********************************************************
23+
/* Test methods
24+
/**********************************************************
25+
*/
26+
27+
final ProtobufMapper MAPPER = new ProtobufMapper();
28+
29+
// [dataformats-binary#68]
30+
public void testWithUUID() throws Exception
31+
{
32+
ProtobufSchema schema = MAPPER.generateSchemaFor(UUIDBean.class);
33+
assertNotNull(schema);
34+
}
35+
36+
// [dataformats-binary#68]
37+
public void testWithShort() throws Exception
38+
{
39+
ProtobufSchema schema = MAPPER.generateSchemaFor(ShortBean.class);
40+
assertNotNull(schema);
41+
}
42+
}

protobuf/src/test/java/com/fasterxml/jackson/dataformat/protobuf/schemagen/SchemaGenTest.java

+27-21
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
1616
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader;
1717

18-
public class SchemaGenTest extends ProtobufTestBase {
19-
18+
public class SchemaGenTest extends ProtobufTestBase
19+
{
2020
public static class WithNestedClass {
2121
@JsonProperty(required = true)
2222
public String name;
@@ -64,26 +64,13 @@ public static class Employee {
6464
public String[] emails;
6565

6666
public Employee boss;
67-
}
68-
69-
protected RootType buildRootType() {
70-
RootType rType = new RootType();
71-
rType.name = "rTpye";
72-
rType.value = 100;
73-
rType.other = new ArrayList<String>();
74-
rType.other.add("12345");
75-
rType.other.add("abcdefg");
76-
return rType;
77-
}
67+
}
7868

79-
protected Employee buildEmployee() {
80-
Employee empl = new Employee();
81-
empl.name = "Bobbee";
82-
empl.age = 39;
83-
empl.emails = new String[] { "[email protected]", "[email protected]" };
84-
empl.boss = null;
85-
return empl;
86-
}
69+
/*
70+
/**********************************************************
71+
/* Test methods
72+
/**********************************************************
73+
*/
8774

8875
public void testWithNestedClass() throws Exception {
8976
ObjectMapper mapper = new ObjectMapper(new ProtobufFactory());
@@ -186,4 +173,23 @@ public void testSimplePojoGenProtobufSchema() throws Exception {
186173
assertEquals(rType.value, parsedRootType.value);
187174
assertEquals(rType.other, parsedRootType.other);
188175
}
176+
177+
protected RootType buildRootType() {
178+
RootType rType = new RootType();
179+
rType.name = "rTpye";
180+
rType.value = 100;
181+
rType.other = new ArrayList<String>();
182+
rType.other.add("12345");
183+
rType.other.add("abcdefg");
184+
return rType;
185+
}
186+
187+
protected Employee buildEmployee() {
188+
Employee empl = new Employee();
189+
empl.name = "Bobbee";
190+
empl.age = 39;
191+
empl.emails = new String[] { "[email protected]", "[email protected]" };
192+
empl.boss = null;
193+
return empl;
194+
}
189195
}

0 commit comments

Comments
 (0)