-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
682 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
guava/src/main/java/tools/jackson/datatype/guava/deser/table/HashBasedTableDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package tools.jackson.datatype.guava.deser.table; | ||
|
||
import tools.jackson.databind.ValueDeserializer; | ||
import tools.jackson.databind.KeyDeserializer; | ||
import tools.jackson.databind.deser.NullValueProvider; | ||
import tools.jackson.databind.jsontype.TypeDeserializer; | ||
import tools.jackson.databind.type.MapLikeType; | ||
|
||
import com.google.common.collect.HashBasedTable; | ||
|
||
/** | ||
* Provides deserialization for the Guava HashBasedTable class. | ||
* | ||
* @author Abhishekkr3003 | ||
*/ | ||
public class HashBasedTableDeserializer | ||
extends MutableTableDeserializer<HashBasedTable<Object, Object, Object>> | ||
{ | ||
public HashBasedTableDeserializer(MapLikeType type) { | ||
super(type); | ||
} | ||
|
||
public HashBasedTableDeserializer(MapLikeType type, KeyDeserializer rowDeserializer, | ||
KeyDeserializer columnDeserializer, TypeDeserializer elementTypeDeserializer, | ||
ValueDeserializer<?> elementDeserializer, NullValueProvider nvp) { | ||
super(type, rowDeserializer, columnDeserializer, elementTypeDeserializer, | ||
elementDeserializer, nvp | ||
); | ||
} | ||
|
||
@Override | ||
protected HashBasedTable<Object, Object, Object> createTable() { | ||
return HashBasedTable.create(); | ||
} | ||
|
||
@Override | ||
protected ValueDeserializer<?> _createContextual(MapLikeType type, | ||
KeyDeserializer rowDeserializer, | ||
KeyDeserializer columnDeserializer, TypeDeserializer typeDeserializer, | ||
ValueDeserializer<?> elementDeserializer, NullValueProvider nvp) { | ||
return new HashBasedTableDeserializer(type, | ||
rowDeserializer, columnDeserializer, typeDeserializer, elementDeserializer, nvp); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
guava/src/main/java/tools/jackson/datatype/guava/deser/table/ImmutableTableDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package tools.jackson.datatype.guava.deser.table; | ||
|
||
import tools.jackson.core.JsonParser; | ||
import tools.jackson.core.JsonToken; | ||
|
||
import tools.jackson.databind.DeserializationContext; | ||
import tools.jackson.databind.ValueDeserializer; | ||
import tools.jackson.databind.KeyDeserializer; | ||
import tools.jackson.databind.deser.NullValueProvider; | ||
import tools.jackson.databind.jsontype.TypeDeserializer; | ||
import tools.jackson.databind.type.MapLikeType; | ||
import tools.jackson.databind.util.AccessPattern; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.ImmutableTable; | ||
|
||
/** | ||
* Provides deserialization for the Guava ImmutableTable class. | ||
* | ||
* @author Abhishekkr3003 | ||
*/ | ||
public class ImmutableTableDeserializer | ||
extends TableDeserializer<ImmutableTable<Object, Object, Object>> | ||
{ | ||
public ImmutableTableDeserializer(MapLikeType type) { | ||
super(type); | ||
} | ||
|
||
protected ImmutableTableDeserializer(MapLikeType type, KeyDeserializer rowDeserializer, | ||
KeyDeserializer colDeserializer, ValueDeserializer<?> valueDeserializer, | ||
TypeDeserializer valueTypeDeserializer, NullValueProvider nuller) { | ||
super(type, rowDeserializer, colDeserializer, valueTypeDeserializer, valueDeserializer, | ||
nuller | ||
); | ||
} | ||
|
||
@Override | ||
public AccessPattern getEmptyAccessPattern() { | ||
// immutable, hence: | ||
return AccessPattern.CONSTANT; | ||
} | ||
|
||
|
||
@Override | ||
public Object getEmptyValue(DeserializationContext ctxt) { | ||
return ImmutableMap.of(); | ||
} | ||
|
||
protected ImmutableTable.Builder<Object, Object, Object> createBuilder() { | ||
return ImmutableTable.builder(); | ||
} | ||
|
||
@Override | ||
public ImmutableTable<Object, Object, Object> deserialize(JsonParser p, | ||
DeserializationContext ctxt) | ||
{ | ||
ImmutableTable.Builder<Object, Object, Object> table = createBuilder(); | ||
|
||
JsonToken currToken = p.currentToken(); | ||
if (currToken != JsonToken.PROPERTY_NAME && currToken != JsonToken.END_OBJECT) { | ||
expect(ctxt, JsonToken.START_OBJECT, currToken); | ||
currToken = p.nextToken(); | ||
} | ||
|
||
for (; currToken == JsonToken.PROPERTY_NAME; currToken = p.nextToken()) { | ||
final Object rowKey; | ||
if (_rowDeserializer != null) { | ||
rowKey = _rowDeserializer.deserializeKey(p.currentName(), ctxt); | ||
} else { | ||
rowKey = p.currentName(); | ||
} | ||
|
||
currToken = p.nextToken(); | ||
expect(ctxt, JsonToken.START_OBJECT, currToken); | ||
|
||
for ( | ||
currToken = p.nextToken(); currToken == JsonToken.PROPERTY_NAME; | ||
currToken = p.nextToken()) { | ||
final Object colKey; | ||
if (_colDeserializer != null) { | ||
colKey = _colDeserializer.deserializeKey(p.currentName(), ctxt); | ||
} else { | ||
colKey = p.currentName(); | ||
} | ||
|
||
p.nextToken(); | ||
|
||
final Object value; | ||
if (p.currentToken() == JsonToken.VALUE_NULL) { | ||
if (_skipNullValues) { | ||
continue; | ||
} | ||
value = _nullProvider.getNullValue(ctxt); | ||
} else if (_valueTypeDeserializer != null) { | ||
value = _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer); | ||
} else { | ||
value = _valueDeserializer.deserialize(p, ctxt); | ||
} | ||
table.put(rowKey, colKey, value); | ||
} | ||
expect(ctxt, JsonToken.END_OBJECT, p.currentToken()); | ||
} | ||
return table.build(); | ||
} | ||
|
||
@Override | ||
protected ValueDeserializer<?> _createContextual(MapLikeType type, | ||
KeyDeserializer rowDeserializer, | ||
KeyDeserializer columnDeserializer, TypeDeserializer valueTypeDeserializer, | ||
ValueDeserializer<?> valueDeserializer, NullValueProvider nullValueProvider) { | ||
return new ImmutableTableDeserializer(type, rowDeserializer, columnDeserializer, | ||
valueDeserializer, valueTypeDeserializer, nullValueProvider | ||
); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
guava/src/main/java/tools/jackson/datatype/guava/deser/table/MutableTableDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package tools.jackson.datatype.guava.deser.table; | ||
|
||
import tools.jackson.core.JsonParser; | ||
import tools.jackson.core.JsonToken; | ||
import tools.jackson.databind.DeserializationContext; | ||
import tools.jackson.databind.KeyDeserializer; | ||
import tools.jackson.databind.ValueDeserializer; | ||
import tools.jackson.databind.deser.NullValueProvider; | ||
import tools.jackson.databind.jsontype.TypeDeserializer; | ||
import tools.jackson.databind.type.MapLikeType; | ||
|
||
import com.google.common.collect.Table; | ||
|
||
/** | ||
* @author Abhishekkr3003 | ||
*/ | ||
public abstract class MutableTableDeserializer<T extends Table<Object, Object, Object>> | ||
extends TableDeserializer<T> | ||
{ | ||
protected MutableTableDeserializer(MapLikeType type) { | ||
super(type); | ||
} | ||
|
||
protected MutableTableDeserializer(MapLikeType _type, KeyDeserializer _rowDeserializer, | ||
KeyDeserializer _colDeserializer, TypeDeserializer _valueTypeDeserializer, | ||
ValueDeserializer<?> _valueDeserializer, NullValueProvider nvp) { | ||
super( | ||
_type, _rowDeserializer, _colDeserializer, _valueTypeDeserializer, _valueDeserializer, | ||
nvp | ||
); | ||
} | ||
|
||
protected abstract T createTable(); | ||
|
||
@Override | ||
protected abstract ValueDeserializer<?> _createContextual(MapLikeType t, KeyDeserializer rkd, | ||
KeyDeserializer ckd, TypeDeserializer vtd, ValueDeserializer<?> vd, NullValueProvider np); | ||
|
||
@Override | ||
public T deserialize(JsonParser p, DeserializationContext ctxt) { | ||
T table = createTable(); | ||
|
||
JsonToken currToken = p.currentToken(); | ||
if (currToken != JsonToken.PROPERTY_NAME && currToken != JsonToken.END_OBJECT) { | ||
expect(ctxt, JsonToken.START_OBJECT, currToken); | ||
currToken = p.nextToken(); | ||
} | ||
|
||
for (; currToken == JsonToken.PROPERTY_NAME; currToken = p.nextToken()) { | ||
final Object rowKey; | ||
if (_rowDeserializer != null) { | ||
rowKey = _rowDeserializer.deserializeKey(p.currentName(), ctxt); | ||
} else { | ||
rowKey = p.currentName(); | ||
} | ||
|
||
currToken = p.nextToken(); | ||
expect(ctxt, JsonToken.START_OBJECT, currToken); | ||
|
||
for ( | ||
currToken = p.nextToken(); currToken == JsonToken.PROPERTY_NAME; | ||
currToken = p.nextToken()) { | ||
final Object colKey; | ||
if (_colDeserializer != null) { | ||
colKey = _colDeserializer.deserializeKey(p.currentName(), ctxt); | ||
} else { | ||
colKey = p.currentName(); | ||
} | ||
|
||
p.nextToken(); | ||
|
||
final Object value; | ||
if (p.currentToken() == JsonToken.VALUE_NULL) { | ||
if (_skipNullValues) { | ||
continue; | ||
} | ||
value = _nullProvider.getNullValue(ctxt); | ||
} else if (_valueTypeDeserializer != null) { | ||
value = _valueDeserializer.deserializeWithType(p, ctxt, _valueTypeDeserializer); | ||
} else { | ||
value = _valueDeserializer.deserialize(p, ctxt); | ||
} | ||
table.put(rowKey, colKey, value); | ||
} | ||
expect(ctxt, JsonToken.END_OBJECT, p.currentToken()); | ||
} | ||
return table; | ||
} | ||
} |
Oops, something went wrong.