Permalink
Browse files

Merge pull request #92 from pgelinas/fix-jackson-2.0

Fix jackson 2.0 support
  • Loading branch information...
2 parents c4b9073 + 4275fe9 commit be1c2ad8be3ecb8fb374117a4ca4f67da1df8229 @helun committed Nov 6, 2012
View
@@ -14,6 +14,10 @@
<dependencies>
<dependency>
+ <groupId>com.fasterxml.jackson.datatype</groupId>
+ <artifactId>jackson-datatype-joda</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
@@ -55,17 +59,14 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
- <version>2.0.0-RC1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
- <version>2.0.0-RC1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
- <version>2.0.0-RC1</version>
</dependency>
</dependencies>
</project>
@@ -79,7 +79,7 @@ public static PageRequest fromLink(String link) {
.decode(link, Base64.URL_SAFE)));
KeyIdPair key = parseNextKey(n);
- int pageSize = n.get(PAGE_SIZE_FIELD_NAME).getIntValue();
+ int pageSize = n.get(PAGE_SIZE_FIELD_NAME).intValue();
boolean back = n.get(BACK_FIELD_NAME).asInt() == 1;
int page = n.get(PAGE_FIELD_NAME).asInt();
return new Builder()
@@ -101,7 +101,7 @@ private static KeyIdPair parseKey(String fieldName, JsonNode n) {
KeyIdPair key;
JsonNode nextKey = n.get(fieldName);
if (nextKey != null) {
- String docId = nextKey.getFieldNames().next();
+ String docId = nextKey.fieldNames().next();
key = new KeyIdPair(nextKey.get(docId), docId);
} else {
key = null;
@@ -1,23 +1,25 @@
package org.ektorp;
-import org.codehaus.jackson.annotate.JsonAnySetter;
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.annotate.JsonProperty;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.ektorp.support.CouchDbDocument;
-
import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
+import org.ektorp.support.CouchDbDocument;
+
+import com.fasterxml.jackson.annotation.JsonAnySetter;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
/**
* Represents Couch documents used by the Couch _replicator database.
*/
-@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@JsonInclude(Include.NON_NULL)
public class ReplicatorDocument extends CouchDbDocument
{
- @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+ @JsonInclude(Include.NON_NULL)
public static class UserContext
{
private String name;
@@ -3,14 +3,16 @@
import java.util.Collections;
import java.util.List;
-import org.codehaus.jackson.map.ObjectMapper;
import org.ektorp.Page;
import org.ektorp.PageRequest;
import org.ektorp.http.HttpResponse;
import org.ektorp.http.StdResponseHandler;
import org.ektorp.util.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
/**
*
* @author henrik
@@ -8,15 +8,16 @@
import java.util.List;
import java.util.Map;
+import org.ektorp.DbAccessException;
+import org.ektorp.ViewResultException;
+
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.ektorp.DbAccessException;
-import org.ektorp.ViewResultException;
public class QueryResultParser<T> {
@@ -131,7 +132,7 @@ private T parseFirstRow(JsonParser jp, ParseState state)
jp.nextToken();
if (isEndOfRow(jp)) {
state.docFieldName = VALUE_FIELD_NAME;
- T doc = mapper.readValue(value, type);
+ T doc = mapper.readValue(value.traverse(), type);
endRow(jp, state);
return doc;
}
@@ -189,7 +190,7 @@ private void skipToField(JsonParser jp, String fieldName, ParseState state)
break;
default:
if (isInField(ID_FIELD_NAME, lastFieldName)) {
- state.lastId = jp.readValueAsTree().getTextValue();
+ state.lastId = jp.<JsonNode>readValueAsTree().asText();
} else if (isInField(KEY_FIELD_NAME, lastFieldName)) {
state.lastKey = jp.readValueAsTree();
} else if (isInField(ERROR_FIELD_NAME, lastFieldName)) {
@@ -4,7 +4,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
+
import org.ektorp.CouchDbConnector;
import org.ektorp.impl.jackson.EktorpJacksonModule;
import org.ektorp.util.Assert;
@@ -9,7 +9,6 @@
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.BeanDeserializer;
import com.fasterxml.jackson.databind.deser.ResolvableDeserializer;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
@@ -29,18 +28,15 @@
private final BeanDeserializer delegate;
private final List<ConstructibleAnnotatedCollection> backReferencedFields;
private final Class<?> clazz;
- private final ObjectMapper objectMapper;
public BackReferencedBeanDeserializer(BeanDeserializer deserializer,
List<ConstructibleAnnotatedCollection> fields,
- CouchDbConnector couchDbConnector, Class<?> clazz,
- ObjectMapper objectMapper) {
+ CouchDbConnector couchDbConnector, Class<?> clazz) {
super(clazz);
this.clazz = clazz;
this.delegate = deserializer;
this.couchDbConnector = couchDbConnector;
this.backReferencedFields = fields;
- this.objectMapper = objectMapper;
}
@Override
@@ -64,12 +60,11 @@ private void addbackReferencedFields(Object deserializedObject,
if (ann.fetch().equals(FetchType.EAGER)) {
handler = new ViewBasedCollection(id, couchDbConnector,
- clazz, ann, constructibleField, objectMapper);
+ clazz, ann, constructibleField);
handler.initialize();
} else {
handler = new LazyLoadingViewBasedCollection(id,
- couchDbConnector, clazz, ann, constructibleField,
- objectMapper);
+ couchDbConnector, clazz, ann, constructibleField);
}
@@ -2,7 +2,6 @@
import java.lang.reflect.*;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.ektorp.*;
import org.ektorp.docref.*;
@@ -14,12 +13,11 @@
public LazyLoadingViewBasedCollection(String id,
CouchDbConnector couchDbConnector, Class<?> clazz,
DocumentReferences documentReferences,
- ConstructibleAnnotatedCollection constructibleField,
- ObjectMapper objectMapper) throws IllegalArgumentException,
+ ConstructibleAnnotatedCollection constructibleField) throws IllegalArgumentException,
InstantiationException, IllegalAccessException,
InvocationTargetException {
super(id, couchDbConnector, clazz, documentReferences,
- constructibleField, objectMapper);
+ constructibleField);
lazyReferences = true;
}
@@ -6,7 +6,6 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
import org.ektorp.*;
import org.ektorp.docref.*;
@@ -23,13 +22,11 @@
final DocumentReferences referenceMetaData;
final ConstructibleAnnotatedCollection constructibleAnnotatedCollection;
final Collection<?> collection;
- final ObjectMapper objectMapper;
private final Collection<BulkDeleteDocument> pendingRemoval = new LinkedHashSet<BulkDeleteDocument>();
public ViewBasedCollection(String id, CouchDbConnector couchDbConnector,
Class<?> clazz, DocumentReferences documentReferences,
- ConstructibleAnnotatedCollection constructibleField,
- ObjectMapper objectMapper) throws IllegalArgumentException,
+ ConstructibleAnnotatedCollection constructibleField) throws IllegalArgumentException,
InstantiationException, IllegalAccessException,
InvocationTargetException {
this.id = id;
@@ -38,7 +35,6 @@ public ViewBasedCollection(String id, CouchDbConnector couchDbConnector,
this.referenceMetaData = documentReferences;
this.constructibleAnnotatedCollection = constructibleField;
this.collection = constructibleField.getConstructor().newInstance();
- this.objectMapper = objectMapper;
}
private List<?> loadFromBackReferences(String thisId,
@@ -9,15 +9,17 @@
import java.util.Map;
import java.util.Set;
+import org.ektorp.docref.DocumentReferences;
+import org.ektorp.impl.NameConventions;
+import org.ektorp.util.Predicate;
+import org.ektorp.util.ReflectionUtils;
+
+import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
import com.fasterxml.jackson.databind.introspect.AnnotatedField;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector;
-import org.ektorp.docref.DocumentReferences;
-import org.ektorp.impl.NameConventions;
-import org.ektorp.util.Predicate;
-import org.ektorp.util.ReflectionUtils;
public class EktorpAnnotationIntrospector extends NopAnnotationIntrospector {
@@ -50,7 +52,14 @@ public boolean isIgnorableMethod(AnnotatedMethod m) {
return names.contains(m.getName());
}
- @Override
+ @Override
+ public String[] findPropertiesToIgnore(Annotated ac) {
+ if(ac instanceof AnnotatedClass){
+ return findPropertiesToIgnore((AnnotatedClass) ac);
+ }
+ return super.findPropertiesToIgnore(ac);
+ }
+
public String[] findPropertiesToIgnore(AnnotatedClass ac) {
List<String> ignoreFields = null;
for (AnnotatedField f : ac.fields()) {
@@ -63,7 +63,7 @@ public EktorpBeanDeserializerModifier(CouchDbConnector db, ObjectMapper objectMa
if (!fields.isEmpty()) {
return new BackReferencedBeanDeserializer(
(BeanDeserializer) deserializer, fields, db, beanDesc
- .getType().getRawClass(), objectMapper);
+ .getType().getRawClass());
}
}
return super.modifyDeserializer(config, beanDesc, deserializer);
@@ -1,13 +1,14 @@
package org.ektorp.support;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.JsonParser;
-import org.codehaus.jackson.JsonToken;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
/**
* A document's MIME multipart/related representation produced by CouchDB
* uses the order of the attachments in the JSON _attachments object as the
@@ -1,17 +1,18 @@
package org.ektorp;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.junit.Before;
-import org.junit.Test;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.junit.Assert.assertThat;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
public class ReplicatorDocumentTest
{
@@ -1,17 +1,18 @@
package org.ektorp;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.junit.Before;
-import org.junit.Test;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.core.IsNull.notNullValue;
-import static org.junit.Assert.assertThat;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
public class ReplicatorDocument_UserContextTest
{
@@ -17,6 +17,8 @@
import java.util.*;
import org.apache.commons.io.IOUtils;
+import com.fasterxml.jackson.datatype.joda.JodaModule;
+
import org.ektorp.*;
import org.ektorp.http.HttpResponse;
import org.ektorp.http.StdHttpClient;
@@ -38,14 +40,22 @@
private static final String OK_RESPONSE_WITH_ID_AND_REV = "{\"ok\":true,\"id\":\"some_id\",\"rev\":\"123D123\"}";
private static final String TEST_DB_PATH = "/test_db/";
- StdCouchDbConnector dbCon;
+ CouchDbConnector dbCon;
StdHttpClient httpClient;
TestDoc td = new TestDoc();
@Before
public void setUp() throws Exception {
httpClient = mock(StdHttpClient.class);
- dbCon = new StdCouchDbConnector("test_db/", new StdCouchDbInstance(httpClient));
+ StdCouchDbInstance dbInstance = new StdCouchDbInstance(httpClient, new StdObjectMapperFactory(){
+ @Override
+ public ObjectMapper createObjectMapper(CouchDbConnector connector) {
+ ObjectMapper mapper = super.createObjectMapper(connector);
+ mapper.registerModule(new JodaModule());
+ return mapper;
+ }
+ });
+ dbCon = dbInstance.createConnector("test_db/",false);
td.name = "nisse";
td.age = 12;
@@ -58,7 +58,7 @@ public void setUp() throws Exception {
@SuppressWarnings("unchecked")
private void setupHandlerAndProxy(DocumentReferences cascadeNone) {
try {
- collectionHandler = new ViewBasedCollection("test", db, TestType.class, cascadeNone, cac, mapper);
+ collectionHandler = new ViewBasedCollection("test", db, TestType.class, cascadeNone, cac);
} catch (Exception e) {
throw Exceptions.propagate(e);
}
Oops, something went wrong.

0 comments on commit be1c2ad

Please sign in to comment.