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

Commit 67d84db

Browse files
committed
Minor tweaks to #79
1 parent d00da16 commit 67d84db

File tree

7 files changed

+36
-28
lines changed

7 files changed

+36
-28
lines changed

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<groupId>com.fasterxml.jackson.datatype</groupId>
99
<artifactId>jackson-datatype-guava</artifactId>
1010
<name>Jackson-datatype-Guava</name>
11-
<version>2.6.2-SNAPSHOT</version>
11+
<version>2.7.0-SNAPSHOT</version>
1212
<packaging>bundle</packaging>
1313
<description>Add-on datatype-support module for Jackson (https://github.com/FasterXML/jackson) that handles
1414
Guava (http://code.google.com/p/guava-libraries/) types (currently mostly just collection ones)
@@ -29,7 +29,7 @@ Guava (http://code.google.com/p/guava-libraries/) types (currently mostly just c
2929
</contributors>
3030

3131
<properties>
32-
<version.jackson>2.6.1</version.jackson>
32+
<version.jackson.core>2.7.0-SNAPSHOT</version.jackson.core>
3333

3434
<version.guava>15.0</version.guava>
3535
<version.guava.osgi>${version.guava}.0</version.guava.osgi>
@@ -66,12 +66,12 @@ com.fasterxml.jackson.databind.util
6666
<dependency>
6767
<groupId>com.fasterxml.jackson.core</groupId>
6868
<artifactId>jackson-databind</artifactId>
69-
<version>${version.jackson}</version>
69+
<version>${version.jackson.core}</version>
7070
</dependency>
7171
<dependency>
7272
<groupId>com.fasterxml.jackson.core</groupId>
7373
<artifactId>jackson-core</artifactId>
74-
<version>${version.jackson}</version>
74+
<version>${version.jackson.core}</version>
7575
</dependency>
7676
<dependency>
7777
<groupId>com.google.guava</groupId>

release-notes/CREDITS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ Alexey Kobyakov (akobiakov@github)
2020
* Reported #64: `@JsonUnwrapped` annotation is ignored when a field is an Optional
2121
(2.6.0)
2222

23+
Jonathan Rodrigues de Oliveira (jorool@github)
24+
25+
* Contributed #79: New configuration for Guava Range default bound type.
26+
(2.7.0)

release-notes/VERSION

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Project: jackson-datatype-guava
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.7.0 (not yet released)
8+
9+
#79: New configuration for Guava Range default bound type.
10+
(contributed by Jonathan R-d-O)
11+
712
2.6.1 (09-Aug-2015)
813

914
No changes since 2.6.0

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
public class GuavaDeserializers
2626
extends Deserializers.Base
2727
{
28-
private BoundType _defaultBoundType;
28+
protected BoundType _defaultBoundType;
29+
30+
public GuavaDeserializers() {
31+
this(null);
32+
}
2933

3034
public GuavaDeserializers(BoundType defaultBoundType) {
3135
_defaultBoundType = defaultBoundType;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.fasterxml.jackson.core.Version;
44

55
import com.fasterxml.jackson.databind.*;
6-
import com.fasterxml.jackson.databind.cfg.PackageVersion;
76
import com.fasterxml.jackson.datatype.guava.ser.GuavaBeanSerializerModifier;
87
import com.google.common.collect.BoundType;
98

src/main/java/com/fasterxml/jackson/datatype/guava/deser/RangeDeserializer.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,18 @@ public class RangeDeserializer
4040
/* Life-cycle
4141
/**********************************************************
4242
*/
43+
44+
/**
45+
* @deprecated Since 2.7
46+
*/
47+
@Deprecated // since 2.7
48+
public RangeDeserializer(JavaType rangeType) {
49+
this(null, rangeType);
50+
}
4351

4452
public RangeDeserializer(BoundType defaultBoundType, JavaType rangeType) {
4553
this(rangeType, null);
46-
this._defaultBoundType = defaultBoundType;
54+
_defaultBoundType = defaultBoundType;
4755
}
4856

4957
@SuppressWarnings("unchecked")
@@ -90,14 +98,14 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
9098
@Override
9199
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt,
92100
TypeDeserializer typeDeserializer)
93-
throws IOException, JsonProcessingException
101+
throws IOException
94102
{
95103
return typeDeserializer.deserializeTypedFromObject(jp, ctxt);
96104
}
97105

98106
@Override
99107
public Range<?> deserialize(JsonParser parser, DeserializationContext context)
100-
throws IOException, JsonProcessingException
108+
throws IOException
101109
{
102110
// NOTE: either START_OBJECT _or_ FIELD_NAME fine; latter for polymorphic cases
103111
JsonToken t = parser.getCurrentToken();
@@ -107,43 +115,32 @@ public Range<?> deserialize(JsonParser parser, DeserializationContext context)
107115

108116
Comparable<?> lowerEndpoint = null;
109117
Comparable<?> upperEndpoint = null;
110-
BoundType lowerBoundType = null;
111-
BoundType upperBoundType = null;
118+
BoundType lowerBoundType = _defaultBoundType;
119+
BoundType upperBoundType = _defaultBoundType;
112120

113121
for (; t != JsonToken.END_OBJECT; t = parser.nextToken()) {
114122
expect(parser, JsonToken.FIELD_NAME, t);
115123
String fieldName = parser.getCurrentName();
116124
try {
117125
if (fieldName.equals("lowerEndpoint")) {
118-
Preconditions.checkState(lowerEndpoint == null, "'lowerEndpoint' field included multiple times.");
119126
parser.nextToken();
120127
lowerEndpoint = deserializeEndpoint(parser, context);
121128
} else if (fieldName.equals("upperEndpoint")) {
122-
Preconditions.checkState(upperEndpoint == null, "'upperEndpoint' field included multiple times.");
123129
parser.nextToken();
124130
upperEndpoint = deserializeEndpoint(parser, context);
125131
} else if (fieldName.equals("lowerBoundType")) {
126-
Preconditions.checkState(lowerBoundType == null, "'lowerBoundType' field included multiple times.");
127132
parser.nextToken();
128133
lowerBoundType = deserializeBoundType(parser);
129134
} else if (fieldName.equals("upperBoundType")) {
130-
Preconditions.checkState(upperBoundType == null, "'upperBoundType' field included multiple times.");
131135
parser.nextToken();
132136
upperBoundType = deserializeBoundType(parser);
133137
} else {
134138
throw context.mappingException("Unexpected Range field: " + fieldName);
135139
}
136140
} catch (IllegalStateException e) {
137-
throw new JsonMappingException(e.getMessage());
141+
throw JsonMappingException.from(parser, e.getMessage());
138142
}
139143
}
140-
141-
if (lowerBoundType == null)
142-
lowerBoundType = _defaultBoundType;
143-
144-
if (upperBoundType == null)
145-
upperBoundType = _defaultBoundType;
146-
147144
try {
148145
if ((lowerEndpoint != null) && (upperEndpoint != null)) {
149146
Preconditions.checkState(lowerEndpoint.getClass() == upperEndpoint.getClass(),
@@ -164,7 +161,7 @@ public Range<?> deserialize(JsonParser parser, DeserializationContext context)
164161
}
165162
return RangeFactory.all();
166163
} catch (IllegalStateException e) {
167-
throw new JsonMappingException(e.getMessage());
164+
throw JsonMappingException.from(parser, e.getMessage());
168165
}
169166
}
170167

@@ -190,10 +187,10 @@ private Comparable<?> deserializeEndpoint(JsonParser parser, DeserializationCont
190187
return (Comparable<?>) obj;
191188
}
192189

193-
private void expect(JsonParser jp, JsonToken expected, JsonToken actual) throws JsonMappingException
190+
private void expect(JsonParser p, JsonToken expected, JsonToken actual) throws JsonMappingException
194191
{
195192
if (actual != expected) {
196-
throw new JsonMappingException("Expecting " + expected + ", found " + actual, jp.getCurrentLocation());
193+
throw JsonMappingException.from(p, "Expecting " + expected + ", found " + actual);
197194
}
198195
}
199196
}

src/test/java/com/fasterxml/jackson/datatype/guava/TestVersions.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ public void testPackageVersion()
3131
private void assertVersion(Versioned vers)
3232
{
3333
final Version v = vers.version();
34-
assertFalse("Should find version information (got "+v+")", v.isUknownVersion());
34+
assertFalse("Should find version information (got "+v+")", v.isUnknownVersion());
3535
assertEquals(PackageVersion.VERSION, v);
3636
}
3737
}
38-

0 commit comments

Comments
 (0)