Skip to content

Commit

Permalink
Work on tackling #68, not yet fully fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 29, 2017
1 parent 643981d commit cf7d5ea
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public EnumElementVisitor(SerializerProvider provider, JavaType type,
_builder = EnumElement.builder();
_builder.name(type.getRawClass().getSimpleName());
_builder.documentation("Enum for " + type.toCanonical());

definedTypeElementBuilders.addTypeElement(type, this, isNested);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,23 @@ public TypeElement build() {

@Override
public void property(BeanProperty writer) throws JsonMappingException {
FieldElement fElement = buildFieldElement(writer, Label.REQUIRED);
_builder.addField(fElement);
_builder.addField(buildFieldElement(writer, Label.REQUIRED));
}

@Override
public void property(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) { }
public void property(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) {
throw new UnsupportedOperationException();
}

@Override
public void optionalProperty(BeanProperty writer) throws JsonMappingException {
FieldElement fElement = buildFieldElement(writer, Label.OPTIONAL);
_builder.addField(fElement);
_builder.addField(buildFieldElement(writer, Label.OPTIONAL));
}

@Override
public void optionalProperty(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) { }
public void optionalProperty(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) {
throw new UnsupportedOperationException();
}

protected FieldElement buildFieldElement(BeanProperty writer, Label label) throws JsonMappingException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public JsonStringFormatVisitor expectStringFormat(JavaType type) {

EnumElementVisitor visitor = new EnumElementVisitor(_provider, type, _definedTypeElementBuilders, _isNested);
_builder = visitor;
_definedTypeElementBuilders.addTypeElement(type, visitor, _isNested);
return visitor;
}

Expand Down Expand Up @@ -141,5 +142,4 @@ protected <T> T _throwUnsupported() {
protected <T> T _throwUnsupported(String msg) {
throw new UnsupportedOperationException(msg);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public PojoWithArrays(boolean[] b,
*/

final ProtobufMapper MAPPER = new ProtobufMapper();

public void testMediaItemSimple() throws Exception
{
_testMediaItem(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.fasterxml.jackson.dataformat.protobuf.failing;

import java.util.UUID;

import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper;
import com.fasterxml.jackson.dataformat.protobuf.ProtobufTestBase;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;

public class GenerateSchema68Test extends ProtobufTestBase
{
static class UUIDBean
{
public UUID messageId;
}

static class ShortBean
{
public short version;
}

/*
/**********************************************************
/* Test methods
/**********************************************************
*/

final ProtobufMapper MAPPER = new ProtobufMapper();

// [dataformats-binary#68]
public void testWithUUID() throws Exception
{
ProtobufSchema schema = MAPPER.generateSchemaFor(UUIDBean.class);
assertNotNull(schema);
}

// [dataformats-binary#68]
public void testWithShort() throws Exception
{
ProtobufSchema schema = MAPPER.generateSchemaFor(ShortBean.class);
assertNotNull(schema);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchemaLoader;

public class SchemaGenTest extends ProtobufTestBase {

public class SchemaGenTest extends ProtobufTestBase
{
public static class WithNestedClass {
@JsonProperty(required = true)
public String name;
Expand Down Expand Up @@ -64,26 +64,13 @@ public static class Employee {
public String[] emails;

public Employee boss;
}

protected RootType buildRootType() {
RootType rType = new RootType();
rType.name = "rTpye";
rType.value = 100;
rType.other = new ArrayList<String>();
rType.other.add("12345");
rType.other.add("abcdefg");
return rType;
}
}

protected Employee buildEmployee() {
Employee empl = new Employee();
empl.name = "Bobbee";
empl.age = 39;
empl.emails = new String[] { "bob@aol.com", "bobby@gmail.com" };
empl.boss = null;
return empl;
}
/*
/**********************************************************
/* Test methods
/**********************************************************
*/

public void testWithNestedClass() throws Exception {
ObjectMapper mapper = new ObjectMapper(new ProtobufFactory());
Expand Down Expand Up @@ -186,4 +173,23 @@ public void testSimplePojoGenProtobufSchema() throws Exception {
assertEquals(rType.value, parsedRootType.value);
assertEquals(rType.other, parsedRootType.other);
}

protected RootType buildRootType() {
RootType rType = new RootType();
rType.name = "rTpye";
rType.value = 100;
rType.other = new ArrayList<String>();
rType.other.add("12345");
rType.other.add("abcdefg");
return rType;
}

protected Employee buildEmployee() {
Employee empl = new Employee();
empl.name = "Bobbee";
empl.age = 39;
empl.emails = new String[] { "bob@aol.com", "bobby@gmail.com" };
empl.boss = null;
return empl;
}
}

0 comments on commit cf7d5ea

Please sign in to comment.