Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit 77f6f65

Browse files
committed
minor cleanup, javadoc adds
1 parent a5dfa2c commit 77f6f65

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

src/main/java/com/fasterxml/jackson/datatype/guava/GuavaModule.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void setupModule(SetupContext context)
2828
@Override
2929
public int hashCode()
3030
{
31-
return GuavaModule.class.hashCode();
31+
return NAME.hashCode();
3232
}
3333

3434
@Override

src/main/java/com/fasterxml/jackson/datatype/guava/GuavaSerializers.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,11 @@ public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType typ
6363
}
6464
// since 2.4.5
6565
if (FluentIterable.class.isAssignableFrom(raw)) {
66-
JavaType[] params = config.getTypeFactory().findTypeParameters(type, Iterable.class);
67-
JavaType vt = (params == null || params.length != 1) ? TypeFactory.unknownType() : params[0];
66+
// We can use parameter type that GuavaTypeModifier has kindly resolved for us
67+
JavaType vt = type.containedType(0);
68+
if (vt == null) { // should never happen but
69+
vt = TypeFactory.unknownType();
70+
}
6871
// 04-Dec-2014, tatu: Not 100% sure why latter would fail... need to investigate when I have time
6972
JavaType delegate = config.getTypeFactory().constructParametrizedType(Iterable.class, Iterable.class, vt);
7073
// JavaType delegate = config.getTypeFactory().constructParametrizedType(FluentIterable.class, Iterable.class, vt);

src/main/java/com/fasterxml/jackson/datatype/guava/GuavaTypeModifier.java

+20
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,28 @@
1212
import com.google.common.collect.Multimap;
1313
import com.google.common.collect.Range;
1414

15+
/**
16+
* We need somewhat hacky support for following Guava types:
17+
*<ul>
18+
* <li>FluentIterable: addition of seeming "empty" property should not prevent serialization as
19+
* basic `Iterable` (with standard Jackson (de)serializer)
20+
* </li>
21+
* <li>Multimap: can reuse much/most of standard Map support as long as we make sure it is
22+
* recognized as "Map-like" type (similar to how Scala Maps are supported)
23+
* </li>
24+
* <li>Optional: generic type, simpler, more-efficient to detect parameterization here (although
25+
* not strictly mandatory)
26+
* </li>Range: same as with Optional, might as well resolve generic type information early on
27+
* <li>
28+
* </li>
29+
*</ul>
30+
*/
1531
public class GuavaTypeModifier extends TypeModifier
1632
{
33+
/**
34+
* Set of single-parameter-type types that we can handle using "standard" handling,
35+
* no additional tricks needed.
36+
*/
1737
private final static Class<?>[] SINGLE_PARAM_TYPES = new Class<?>[] {
1838
Range.class, Optional.class
1939
};

src/test/java/com/fasterxml/jackson/datatype/guava/failing/OptionalUnwrappedTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ static class OptionalParent {
3333

3434
public void testUntyped() throws Exception
3535
{
36-
ObjectWriter w = MAPPER.writerWithDefaultPrettyPrinter();
36+
ObjectWriter w = MAPPER.writer();
3737
// String jsonExp = w.writeValueAsString(new Parent());
38-
String jsonExp = aposToQuotes("{\n 'name' : 'Bob'\n}");
38+
String jsonExp = aposToQuotes("{'name':'Bob'}");
3939
String jsonAct = w.writeValueAsString(new OptionalParent());
4040
assertEquals(jsonExp, jsonAct);
4141
}

0 commit comments

Comments
 (0)