Skip to content
Open
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 @@ -13,4 +13,9 @@ public int nextTag(BeanProperty writer) {
throw new IllegalStateException("No index metadata found for " + writer.getFullName()
+ " (usually annotated with @JsonProperty.index): either annotate all properties of type " + writer.getWrapperName().getSimpleName() + " with indexes or none at all");
}

@Override
public int nextTag() {
throw new IllegalStateException("Index metadata not found, (usually annotated with @JsonProperty.index): either annotate all properties with indexes or none at all");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public void property(BeanProperty writer) throws JsonMappingException {
}

@Override
public void property(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) {
throw new UnsupportedOperationException();
public void property(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) throws JsonMappingException {
_builder.addField(buildFieldElement(name, propertyTypeHint, Label.REQUIRED));
}

@Override
Expand All @@ -60,8 +60,8 @@ public void optionalProperty(BeanProperty writer) throws JsonMappingException {
}

@Override
public void optionalProperty(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) {
throw new UnsupportedOperationException();
public void optionalProperty(String name, JsonFormatVisitable handler, JavaType propertyTypeHint) throws JsonMappingException {
_builder.addField(buildFieldElement(name, propertyTypeHint, Label.OPTIONAL));
}

protected FieldElement buildFieldElement(BeanProperty writer, Label label) throws JsonMappingException
Expand All @@ -88,14 +88,41 @@ protected FieldElement buildFieldElement(BeanProperty writer, Label label) throw
return fBuilder.build();
}

protected FieldElement buildFieldElement(String name, JavaType type, Label label) throws JsonMappingException
{
FieldElement.Builder fBuilder = FieldElement.builder();

fBuilder.name(name);
fBuilder.tag(nextTag());

if (type.isArrayType() || type.isCollectionLikeType()) {
if (ProtobufSchemaHelper.isBinaryType(type)) {
fBuilder.label(label);
fBuilder.type(ScalarType.BYTES);
} else {
fBuilder.label(Label.REPEATED);
fBuilder.type(getDataType(type.getContentType()));
}
} else {
fBuilder.label(label);
fBuilder.type(getDataType(type));
}
return fBuilder.build();
}

protected int nextTag() {
getTagGenerator(null);
return _tagGenerator.nextTag();
}

protected int nextTag(BeanProperty writer) {
getTagGenerator(writer);
return _tagGenerator.nextTag(writer);
}

protected void getTagGenerator(BeanProperty writer) {
if (_tagGenerator == null) {
if (ProtobufSchemaHelper.hasIndex(writer)) {
if (writer != null && ProtobufSchemaHelper.hasIndex(writer)) {
_tagGenerator = new AnnotationBasedTagGenerator();
} else {
_tagGenerator = new DefaultTagGenerator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

interface TagGenerator {
int nextTag(BeanProperty writer);

int nextTag();
}