Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Commit

Permalink
Fixed #46 (ugly work-around, but...)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 8, 2014
1 parent 622c91d commit bd64e20
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 17 deletions.
9 changes: 7 additions & 2 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
Project: jackson-datatype-guava
Version: 2.4.1 (17-Jun-2014)
Version: 2.4.2 (xx-Aug-2014)

No changes since 2.4.0.
#46: Can not serialize guava Iterables
(reported by chisui@github)

------------------------------------------------------------------------
=== History: ===
------------------------------------------------------------------------

2.4.1 (17-Jun-2014)

No changes since 2.4.0.

2.4.0 (03-Jun-2014)

#43: Add support for `HostAndPort`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,28 @@ public JavaType modifyType(JavaType type, Type jdkType, TypeBindings context, Ty
* have to do for now...
*/
if (FluentIterable.class.isAssignableFrom(raw)) {
JavaType[] types = typeFactory.findTypeParameters(type, Iterable.class);
JavaType elemType = (types == null || types.length < 1)
? null : types[0];
JavaType elemType = null;
JavaType[] types;
try {
types = typeFactory.findTypeParameters(type, Iterable.class);
if (types != null && types.length > 0) {
elemType = types[0];
}
} catch (IllegalArgumentException e) {
/* 07-Aug-2015, tatu: Nasty hack, but until we get 100% functioning
* type resolution (from ClassMate project, f.ex.), need to work around
* edge cases with aliasing and/or unresolved type variables.
* So... here we go:
*/
String msg = e.getMessage();
if (msg == null || !msg.contains("Type variable 'T' can not be resolved")) {
throw e;
}
}
if (elemType == null) {
elemType = TypeFactory.unknownType();
}
return typeFactory.constructParametricType(Iterable.class, elemType);
return typeFactory.constructParametricType(Iterable.class, elemType);
}
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Unit tests to verify serialization of {@link FluentIterable}s.
*/
public class TestFluentIterable extends BaseTest
public class FluentIterableTest extends ModuleTestBase
{
private final ObjectMapper MAPPER = mapperWithModule();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.net.HostAndPort;

public class HostAndPortTest extends BaseTest
public class HostAndPortTest extends ModuleTestBase
{
private final ObjectMapper MAPPER = mapperWithModule();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.fasterxml.jackson.datatype.guava;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Iterables;

public class IterablesTest extends ModuleTestBase
{
private final ObjectMapper MAPPER = mapperWithModule();

public void testIterablesSerialization() throws Exception
{
String json = MAPPER.writeValueAsString(Iterables.limit(Iterables.cycle(1,2,3), 3));
assertNotNull(json);
assertEquals("[1,2,3]", json);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import com.fasterxml.jackson.datatype.guava.GuavaModule;

public abstract class BaseTest extends junit.framework.TestCase
public abstract class ModuleTestBase extends junit.framework.TestCase
{
protected BaseTest() { }
protected ModuleTestBase() { }

protected ObjectMapper mapperWithModule()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @author tsaloranta
*/
public class TestImmutables extends BaseTest
public class TestImmutables extends ModuleTestBase
{
private final ObjectMapper MAPPER = mapperWithModule();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @author [email protected]
*/
public class TestMultimaps extends BaseTest
public class TestMultimaps extends ModuleTestBase
{
// Test for issue #13 on github, provided by stevenschlansker
public static enum MyEnum {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @author tsaloranta
*/
public class TestMultisets extends BaseTest
public class TestMultisets extends ModuleTestBase
{

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import com.google.common.base.Optional;

public class TestOptional extends BaseTest
public class TestOptional extends ModuleTestBase
{
private final ObjectMapper MAPPER = mapperWithModule();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;

public class TestOptionalWithPolymorphic extends BaseTest
public class TestOptionalWithPolymorphic extends ModuleTestBase
{
static class ContainerA {
@JsonProperty private Optional<String> name = Optional.absent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Unit tests to verify serialization of Guava {@link Range}s.
*/
public class TestRange extends BaseTest {
public class TestRange extends ModuleTestBase {

private final ObjectMapper MAPPER = mapperWithModule();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.fasterxml.jackson.datatype.guava.PackageVersion;

public class TestVersions extends BaseTest
public class TestVersions extends ModuleTestBase
{
public void testMapperVersions() throws IOException
{
Expand Down

0 comments on commit bd64e20

Please sign in to comment.