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

Commit

Permalink
and a fix to wrong import stmt; also, added bit more testing for Rang…
Browse files Browse the repository at this point in the history
…e handling
  • Loading branch information
cowtowncoder committed Sep 22, 2014
1 parent 76005aa commit 959aa0f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import java.lang.reflect.Type;

import org.w3c.dom.ranges.Range;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeBindings;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.type.TypeModifier;

import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Multimap;
import com.google.common.collect.Range;

public class GuavaTypeModifier extends TypeModifier
{
Expand Down
32 changes: 30 additions & 2 deletions src/test/java/com/fasterxml/jackson/datatype/guava/TestRange.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.fasterxml.jackson.datatype.guava;

import com.fasterxml.jackson.annotation.JsonTypeInfo;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.guava.deser.util.RangeFactory;
import com.google.common.base.Objects;

import com.google.common.collect.Range;

import java.io.IOException;
Expand All @@ -23,6 +24,13 @@ protected static class Untyped
public Untyped() { }
public Untyped(Range<?> r) { range = r; }
}

static class Wrapped {
public Range<Integer> r;

public Wrapped() { }
public Wrapped(Range<Integer> r) { this.r = r; }
}

/**
* This test is present so that we know if either Jackson's handling of Range
Expand Down Expand Up @@ -51,6 +59,19 @@ public void testSerialization() throws Exception
testSerialization(MAPPER, RangeFactory.singleton(1));
}

public void testWrappedSerialization() throws Exception
{
testSerializationWrapped(MAPPER, RangeFactory.open(1, 10));
testSerializationWrapped(MAPPER, RangeFactory.openClosed(1, 10));
testSerializationWrapped(MAPPER, RangeFactory.closedOpen(1, 10));
testSerializationWrapped(MAPPER, RangeFactory.closed(1, 10));
testSerializationWrapped(MAPPER, RangeFactory.atLeast(1));
testSerializationWrapped(MAPPER, RangeFactory.greaterThan(1));
testSerializationWrapped(MAPPER, RangeFactory.atMost(10));
testSerializationWrapped(MAPPER, RangeFactory.lessThan(10));
testSerializationWrapped(MAPPER, RangeFactory.singleton(1));
}

public void testDeserialization() throws Exception
{
String json = MAPPER.writeValueAsString(RangeFactory.open(1, 10));
Expand All @@ -65,9 +86,16 @@ private void testSerialization(ObjectMapper objectMapper, Range<?> range) throws
{
String json = objectMapper.writeValueAsString(range);
Range<?> rangeClone = objectMapper.readValue(json, Range.class);
assert Objects.equal(rangeClone, range);
assertEquals(rangeClone, range);
}

private void testSerializationWrapped(ObjectMapper objectMapper, Range<Integer> range) throws IOException
{
String json = objectMapper.writeValueAsString(new Wrapped(range));
Wrapped result = objectMapper.readValue(json, Wrapped.class);
assertEquals(range, result.r);
}

public void testUntyped() throws Exception
{
String json = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(new Untyped(RangeFactory.open(1, 10)));
Expand Down

0 comments on commit 959aa0f

Please sign in to comment.