Skip to content

Commit

Permalink
Fix #148
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 9, 2019
1 parent 0ed8c0d commit 47daf9c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.net.URL;

import com.fasterxml.jackson.core.Version;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -65,7 +65,6 @@ protected ProtobufMapper(ProtobufMapper src) {
/**
* @since 2.10
*/
@SuppressWarnings("unchecked")
public static ProtobufMapper.Builder builder() {
return new Builder(new ProtobufMapper());
}
Expand Down Expand Up @@ -118,7 +117,9 @@ public void setSchemaLoader(ProtobufSchemaLoader l) {
* given Java type. Uses {@link ProtobufSchemaGenerator} for
* generation.
*
* @since 2.8
* @param type Resolved type to generate {@link ProtobufSchema} for
*
* @return Generated {@link ProtobufSchema}
*/
public ProtobufSchema generateSchemaFor(JavaType type) throws JsonMappingException
{
Expand All @@ -129,8 +130,11 @@ public ProtobufSchema generateSchemaFor(JavaType type) throws JsonMappingExcepti

/**
* Convenience method for constructing protoc definition that matches
* given Java type. Uses {@link ProtobufSchemaGenerator} for
* generation.
* given Java type. Uses {@link ProtobufSchemaGenerator} for generation.
*
* @param type Type-erased type to generate {@link ProtobufSchema} for
*
* @return Generated {@link ProtobufSchema}
*
* @since 2.8
*/
Expand All @@ -141,6 +145,20 @@ public ProtobufSchema generateSchemaFor(Class<?> type) throws JsonMappingExcepti
return gen.getGeneratedSchema();
}

/**
* Convenience method for constructing protoc definition that matches
* given Java type. Uses {@link ProtobufSchemaGenerator} for generation.
*
* @param type Type to generate {@link ProtobufSchema} for
*
* @return Generated {@link ProtobufSchema}
*
* @since 2.10
*/
public ProtobufSchema generateSchemaFor(TypeReference<?> type) throws JsonMappingException {
return generateSchemaFor(_typeFactory.constructType(type));
}

/*
/**********************************************************
/* Schema access, FileDescriptorSets (since 2.9)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fasterxml.jackson.dataformat.protobuf;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
Expand Down Expand Up @@ -49,7 +50,7 @@ public void testBigEnum() throws Exception
// type + short id == 2 bytes
assertEquals(2, bytes.length);

ObjectReader r = MAPPER.readerFor(BigEnumWrapper.class).with(schema);
ObjectReader r = MAPPER.readerFor(new TypeReference<BigEnumWrapper> () {}).with(schema);
BigEnumWrapper result = r.readValue(bytes);
assertEquals(input.value, result.value);
}
Expand Down
5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Project: jackson-datatypes-binaryModules:
=== Releases ===
------------------------------------------------------------------------

2.10.0 (not yet released)

#148: (protobuf) Add `ProtobufMapper.generateSchemaFor(TypeReference<?>)` overload
(suggested by MrThreepwood@github)

2.10.0.pr2 (31-Aug-2019)

#168: (avro) `JsonMappingException` for union types with multiple Record types
Expand Down

0 comments on commit 47daf9c

Please sign in to comment.