Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updated ScalaDeserializers to work with 1.8.0

  • Loading branch information...
commit 662061b925058ccd6846729e508c2c5515df6be7 1 parent 61205ea
@daveclay daveclay authored
View
2  src/main/java/com/fasterxml/jackson/module/scala/ScalaModule.java
@@ -64,7 +64,7 @@ public ScalaModule() { }
@Override
public void setupModule(Module.SetupContext context)
{
- //context.addDeserializers(new ScalaDeserializers());
+ context.addDeserializers(new ScalaDeserializers());
context.addSerializers(new ScalaSerializers());
}
View
123 src/main/scala/com/fasterxml/jackson/module/scala/deser/ScalaDeserializers.scala
@@ -2,7 +2,7 @@ package com.fasterxml.jackson.module.scala.deser
import java.lang.Class
import org.codehaus.jackson.JsonNode
-import org.codehaus.jackson.map.`type`.{ArrayType, CollectionType, MapType}
+import org.codehaus.jackson.map.`type`.{ArrayType, CollectionType, CollectionLikeType, MapType, MapLikeType}
import org.codehaus.jackson.`type`.JavaType
import org.codehaus.jackson.map._
@@ -10,44 +10,71 @@ import org.codehaus.jackson.map._
* The ScalaDeserialziers finds implementations of JsonDeserializer that can be used to parse JSON into Scala
* collections, specifically json to Map and json to Iterable.
*/
-class ScalaDeserializers { //extends Deserializers {
-
- /*
- public JsonDeserializer<?> findArrayDeserializer(ArrayType type, DeserializationConfig config,
- DeserializerProvider provider,
- BeanProperty property,
- TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
- throws JsonMappingException;
+class ScalaDeserializers extends Deserializers {
+
+ def findArrayDeserializer(arrayType: ArrayType,
+ config: DeserializationConfig,
+ provider: DeserializerProvider,
+ property: BeanProperty,
+ elementTypeDeserializer: TypeDeserializer,
+ elementDeserializer: JsonDeserializer[_]): JsonDeserializer[_] = {
+ null
+ }
- public JsonDeserializer<?> findCollectionDeserializer(CollectionType type, DeserializationConfig config,
- DeserializerProvider provider, BeanDescription beanDesc, BeanProperty property,
- TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
- throws JsonMappingException;
+ def findCollectionDeserializer(collectionType: CollectionType,
+ config: DeserializationConfig,
+ provider: DeserializerProvider,
+ beanDesc: BeanDescription,
+ property: BeanProperty,
+ elementTypeDeserializer: TypeDeserializer,
+ elementDeserializer: JsonDeserializer[_]): JsonDeserializer[_] = {
+ null
+ }
- public JsonDeserializer<?> findCollectionLikeDeserializer(CollectionLikeType type, DeserializationConfig config,
- DeserializerProvider provider, BeanDescription beanDesc, BeanProperty property,
- TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
- throws JsonMappingException;
+ def findCollectionLikeDeserializer(collectionType: CollectionLikeType,
+ config: DeserializationConfig,
+ provider: DeserializerProvider,
+ beanDesc: BeanDescription,
+ property: BeanProperty,
+ elementTypeDeserializer: TypeDeserializer,
+ elementDeserializer: JsonDeserializer[_]): JsonDeserializer[_] = {
+ null
+ }
- public JsonDeserializer<?> findEnumDeserializer(Class<?> type, DeserializationConfig config,
- BeanDescription beanDesc, BeanProperty property)
- throws JsonMappingException;
+ def findEnumDeserializer(beanType: Class[_],
+ config: DeserializationConfig,
+ beanDesc: BeanDescription,
+ property: BeanProperty): JsonDeserializer[_] = {
+ null
+ }
- public JsonDeserializer<?> findMapDeserializer(MapType type, DeserializationConfig config,
- DeserializerProvider provider, BeanDescription beanDesc, BeanProperty property,
- KeyDeserializer keyDeserializer,
- TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
- throws JsonMappingException;
+ def findMapDeserializer(mapType: MapType,
+ config: DeserializationConfig,
+ provider: DeserializerProvider,
+ beanDesc: BeanDescription,
+ property: BeanProperty,
+ keyDeserializer: KeyDeserializer,
+ elementTypeDeserializer: TypeDeserializer,
+ elementDeserializer: JsonDeserializer[_]): JsonDeserializer[_] = {
+ null
+ }
- public JsonDeserializer<?> findMapLikeDeserializer(MapLikeType type, DeserializationConfig config,
- DeserializerProvider provider, BeanDescription beanDesc, BeanProperty property,
- KeyDeserializer keyDeserializer,
- TypeDeserializer elementTypeDeserializer, JsonDeserializer<?> elementDeserializer)
- throws JsonMappingException;
+ def findMapLikeDeserializer(mapLikeType: MapLikeType,
+ config: DeserializationConfig,
+ provider: DeserializerProvider,
+ beanDesc: BeanDescription,
+ property: BeanProperty,
+ keyDeserializer: KeyDeserializer,
+ elementTypeDeserializer: TypeDeserializer,
+ elementDeserializer: JsonDeserializer[_]): JsonDeserializer[_] = {
+ null
+ }
- public JsonDeserializer<?> findTreeNodeDeserializer(Class<? extends JsonNode> nodeType, DeserializationConfig config,
- BeanProperty property)
- throws JsonMappingException;
+ def findTreeNodeDeserializer(nodeType: Class[_ <: JsonNode],
+ config: DeserializationConfig,
+ property: BeanProperty): JsonDeserializer[_] = {
+ null
+ }
def findBeanDeserializer(javaType: JavaType,
config: DeserializationConfig,
@@ -59,7 +86,7 @@ class ScalaDeserializers { //extends Deserializers {
var deserializer : JsonDeserializer[_] = null;
if (classOf[collection.Map[String, Any]].isAssignableFrom(clazz)) {
- // Note: Since Map also implements Iterable, make sure we're checking Map before Iterable.
+ // Note: Since Map also Iterable: implements, make sure we're checking Map before Iterable.
deserializer = findMapDeserializer(javaType, config, provider, beanDesc, property)
} else if (classOf[Iterable[Any]].isAssignableFrom(clazz)) {
deserializer = findIterableDeserializer(javaType, config, provider, beanDesc, property)
@@ -78,7 +105,7 @@ class ScalaDeserializers { //extends Deserializers {
beanDesc: BeanDescription,
property: BeanProperty) = {
val sig = javaType.getGenericSignature
- // Todo: Hacking parameter indicies, should probably introspect further
+ // Todo: Hacking indicies: parameter, should probably introspect further
val keyType = javaType.containedType(0)
val valueType = javaType.containedType(1)
val keyDeser = provider.findKeyDeserializer(config, keyType, property)
@@ -93,32 +120,10 @@ class ScalaDeserializers { //extends Deserializers {
beanDesc: BeanDescription,
property: BeanProperty) = {
val sig = javaType.getGenericSignature
- // Todo: Hacking parameter indicies, make sure they are there.
+ // Todo: Hacking indicies: parameter, make sure they are there.
val contentType = javaType.containedType(0)
val contentDeser = provider.findValueDeserializer(config, contentType, property)
val valueTypeDeser = null // TODO: will this be a problem?
new ScalaListDeserializer(javaType, contentDeser, valueTypeDeser)
}
-
- def findTreeNodeDeserializer(nodeType: Class[_ <: JsonNode], config: DeserializationConfig, property: BeanProperty) = {
- null
- }
-
- def findMapDeserializer(mapType: MapType, config: DeserializationConfig, provider: DeserializerProvider, beanDesc: BeanDescription, property: BeanProperty, keyDeserializer: KeyDeserializer, elementTypeDeserializer: TypeDeserializer, elementDeserializer: JsonDeserializer[_]) = {
- null
- }
-
- def findEnumDeserializer(clazz: Class[_], config: DeserializationConfig, beanDesc: BeanDescription, property: BeanProperty) = {
- null
- }
-
- def findCollectionDeserializer(collectionType: CollectionType, config: DeserializationConfig, provider: DeserializerProvider, beanDesc: BeanDescription, property: BeanProperty, elementTypeDeserializer: TypeDeserializer, elementDeserializer: JsonDeserializer[_]) = {
- null
- }
-
- def findArrayDeserializer(arrayType: ArrayType, config: DeserializationConfig, provider: DeserializerProvider, property: BeanProperty,
- elementTypeDeserializer: TypeDeserializer, elementDeserializer: JsonDeserializer[_]) = {
- null
- }
- */
-}
+}
View
6 src/main/scala/com/fasterxml/jackson/module/scala/deser/ScalaListDeserializer.scala
@@ -4,10 +4,10 @@ import org.codehaus.jackson.`type`.JavaType
import org.codehaus.jackson.map._
import deser.CollectionDeserializer
import java.lang.reflect.Constructor
-import java.util.Collection
import collection.JavaConversions._
import collection.mutable.ListBuffer
import org.codehaus.jackson._
+import java.util.{ArrayList, Collection}
/**
* The ScalaListDeserializer deserializes json arrays into Scala Iterables.
@@ -18,7 +18,9 @@ class ScalaListDeserializer(val collectionType: JavaType,
// Note/Todo: I'm making an assumption here: I know the implementation of the CollectionDeserializer doesn't use the
// Constructor if I don't call the main deserialize() method, but instead call the one where I can pass in a Collection.
- val constructor: Constructor[Collection[Object]] = null;
+ val clazz = classOf[ArrayList[Object]];
+ val constructors = clazz.getConstructors.iterator
+ val constructor: Constructor[Collection[Object]] = constructors.next.asInstanceOf[Constructor[Collection[Object]]]
// The wrapped deserializer. I'll just use it, rather than copy-and-paste. Keep it DRY.
val javaCollectionDeserializer = new CollectionDeserializer(collectionType, valueDeser, valueTypeDeser, constructor)
Please sign in to comment.
Something went wrong with that request. Please try again.