Skip to content

Commit

Permalink
change gson to jackson
Browse files Browse the repository at this point in the history
  • Loading branch information
need4spd committed Oct 28, 2013
1 parent 8d6e4db commit 5b3bcd1
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 69 deletions.
16 changes: 12 additions & 4 deletions crescent_core_web/build.gradle
Expand Up @@ -24,7 +24,6 @@ dependencies {
[group: 'org.springframework', name: 'org.springframework.web', version: '3.1.2.RELEASE'],
[group: 'org.springframework', name: 'org.springframework.core', version: '3.1.2.RELEASE'],
[group: 'org.springframework', name: 'org.springframework.test', version: '3.1.2.RELEASE'],
[group: 'com.google.code.gson', name: 'gson', version: '2.2.2'],
[group: 'jaxen', name: 'jaxen', version: '1.1.4'],
[group: 'dom4j', name: 'dom4j', version: '1.6.1'],
[group: 'javax.servlet', name: 'servlet-api', version: '2.5'],
Expand All @@ -37,7 +36,12 @@ dependencies {
[group: 'ch.qos.logback', name: 'logback-core', version: "${versions.logback}"],
[group: 'ch.qos.logback', name: 'logback-classic', version: "${versions.logback}"],
[group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.7.5'],
[group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.1.6']
[group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.1.6'],
[group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.13'],
[group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.2.3'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.2.3'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.2.3']
)

testRuntime(
Expand All @@ -52,7 +56,6 @@ dependencies {
[group: 'org.springframework', name: 'org.springframework.web', version: '3.1.2.RELEASE'],
[group: 'org.springframework', name: 'org.springframework.core', version: '3.1.2.RELEASE'],
[group: 'org.springframework', name: 'org.springframework.test', version: '3.1.2.RELEASE'],
[group: 'com.google.code.gson', name: 'gson', version: '2.2.2'],
[group: 'jaxen', name: 'jaxen', version: '1.1.4'],
[group: 'dom4j', name: 'dom4j', version: '1.6.1'],
[group: 'javax.servlet', name: 'servlet-api', version: '2.5'],
Expand All @@ -64,7 +67,12 @@ dependencies {
[group: 'ch.qos.logback', name: 'logback-core', version: "${versions.logback}"],
[group: 'ch.qos.logback', name: 'logback-classic', version: "${versions.logback}"],
[group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.7.5'],
[group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.1.6']
[group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.1.6'],
[group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.13'],
[group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.2.3'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.2.3'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.2.3']
)

}
Expand Down
Expand Up @@ -52,7 +52,7 @@ private void initIndexWriter() {
dir = FSDirectory.open(new File(indexDir));
}

IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_35, crescentCollection.getIndexingModeAnalyzer());
IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_44, crescentCollection.getIndexingModeAnalyzer());
conf.setOpenMode(OpenMode.CREATE_OR_APPEND);
//conf.setIndexDeletionPolicy(new LastCommitDeletePolicy());

Expand Down
Expand Up @@ -9,6 +9,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -17,7 +18,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.google.gson.Gson;
import com.tistory.devyongsik.crescent.admin.entity.MorphResult;
import com.tistory.devyongsik.crescent.admin.entity.MorphToken;
import com.tistory.devyongsik.crescent.admin.service.MorphService;
Expand Down Expand Up @@ -116,8 +116,6 @@ public void morphTestAjax(HttpServletRequest request, HttpServletResponse respon
List<MorphResult> morphIndexingTestResult = new ArrayList<MorphResult>();
List<MorphResult> morphQueryTestResult = new ArrayList<MorphResult>();

Gson gson = new Gson();

Map<String, List<MorphResult>> morphTestResultSet = new HashMap<String, List<MorphResult>>();

for(MorphToken token : resultTokenListIndexingMode) {
Expand All @@ -143,7 +141,8 @@ public void morphTestAjax(HttpServletRequest request, HttpServletResponse respon
morphTestResultSet.put("indexResult", morphIndexingTestResult);
morphTestResultSet.put("queryResult", morphQueryTestResult);

String morphResult = gson.toJson(morphTestResultSet);
ObjectMapper mapper = new ObjectMapper();
String morphResult = mapper.writeValueAsString(morphTestResultSet);

logger.info("morphResult : {}", morphResult);

Expand Down
@@ -1,9 +1,11 @@
package com.tistory.devyongsik.crescent.data.handler;

import java.io.IOException;

import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.Gson;
import com.tistory.devyongsik.crescent.index.entity.IndexingRequestForm;

/**
Expand All @@ -15,21 +17,18 @@ public class JsonDataHandler implements Handler {
private Logger logger = LoggerFactory.getLogger(JsonDataHandler.class);

@Override
public IndexingRequestForm handledData(String jonsFormStr) {

Gson gson = new Gson();

//logger.debug("jonsFormStr : {}", jonsFormStr);
public IndexingRequestForm handledData(String jsonFormStr) {

try {
ObjectMapper mapper = new ObjectMapper();

IndexingRequestForm indexingRequestForm = gson.fromJson(jonsFormStr, IndexingRequestForm.class);
IndexingRequestForm indexingRequestForm = mapper.readValue(jsonFormStr, IndexingRequestForm.class);

return indexingRequestForm;

} catch (Exception e) {
} catch (IOException e) {
logger.error("error : ", e);
throw new IllegalStateException("색인 대상 문서를 변환 중 에러가 발생하였습니다. [" + jonsFormStr +"]");
throw new IllegalStateException("색인 대상 문서를 변환 중 에러가 발생하였습니다. [" + jsonFormStr +"]");
}
}
}
@@ -1,13 +1,26 @@
package com.tistory.devyongsik.crescent.search;

import com.google.gson.Gson;
import java.io.IOException;

import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JsonFormConverter {

private Logger logger = LoggerFactory.getLogger(getClass());

public String convert(Object targetObject) {
Gson gson = new Gson();
String json = gson.toJson(targetObject);

return json;
try {

ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(targetObject);
return json;

} catch (IOException e) {
logger.error("Exception while make json form string.", e);
throw new IllegalStateException("Exception while make json form string.", e);
}
}
}
@@ -1,14 +1,17 @@
package com.tistory.devyongsik.crescent.utils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.Gson;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

public class SampleDataMaker {
public static void main(String[] args) {
public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException {

List<Map<String, String>> sampleList = new ArrayList<Map<String, String>>();
String field_name_1 = "wiki_idx";
Expand All @@ -30,8 +33,8 @@ public static void main(String[] args) {
sampleList.add(doc);
}

Gson gson = new Gson();
String sampleData = gson.toJson(sampleList);
ObjectMapper mapper = new ObjectMapper();
String sampleData = mapper.writeValueAsString(sampleList);

System.out.println(sampleData);
}
Expand Down
@@ -1,10 +1,12 @@
package com.tistory.devyongsik.crescent.data.handler;

import java.io.IOException;

import junit.framework.Assert;

import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Test;

import com.google.gson.Gson;
import com.tistory.devyongsik.crescent.index.entity.IndexingRequestForm;
import com.tistory.devyongsik.utils.FormattedTextBuilder;

Expand All @@ -14,9 +16,13 @@ public class JsonDataHandlerTest {
public void indexingAddDocumentBulk() {
String inputText = FormattedTextBuilder.getAddDocBulkJsonForm();

Gson gson = new Gson();

IndexingRequestForm indexingRequest = gson.fromJson(inputText, IndexingRequestForm.class);
ObjectMapper mapper = new ObjectMapper();
IndexingRequestForm indexingRequest = null;
try {
indexingRequest = mapper.readValue(inputText, IndexingRequestForm.class);
} catch (IOException e) {
Assert.fail(e.getMessage());
}

Assert.assertEquals("add", indexingRequest.getCommand());
Assert.assertEquals(null, indexingRequest.getQuery());
Expand All @@ -29,9 +35,13 @@ public void indexingAddDocumentBulk() {
public void indexingAddDocumentIncrement() {
String inputText = FormattedTextBuilder.getAddDocIncJsonForm();

Gson gson = new Gson();

IndexingRequestForm indexingRequest = gson.fromJson(inputText, IndexingRequestForm.class);
ObjectMapper mapper = new ObjectMapper();
IndexingRequestForm indexingRequest = null;
try {
indexingRequest = mapper.readValue(inputText, IndexingRequestForm.class);
} catch (IOException e) {
Assert.fail(e.getMessage());
}

Assert.assertEquals("add", indexingRequest.getCommand());
Assert.assertEquals(null, indexingRequest.getQuery());
Expand All @@ -44,9 +54,13 @@ public void indexingAddDocumentIncrement() {
public void indexingUpdateDocumentBulk() {
String inputText = FormattedTextBuilder.getUpdateDocBulkJsonForm();

Gson gson = new Gson();

IndexingRequestForm indexingRequest = gson.fromJson(inputText, IndexingRequestForm.class);
ObjectMapper mapper = new ObjectMapper();
IndexingRequestForm indexingRequest = null;
try {
indexingRequest = mapper.readValue(inputText, IndexingRequestForm.class);
} catch (IOException e) {
Assert.fail(e.getMessage());
}

Assert.assertEquals("update", indexingRequest.getCommand());
Assert.assertEquals("creuser:test", indexingRequest.getQuery());
Expand All @@ -59,9 +73,14 @@ public void indexingUpdateDocumentBulk() {
public void indexingUpdateDocumentInc() {
String inputText = FormattedTextBuilder.getUpdateDocIncJsonForm();

Gson gson = new Gson();
ObjectMapper mapper = new ObjectMapper();
IndexingRequestForm indexingRequest = null;
try {
indexingRequest = mapper.readValue(inputText, IndexingRequestForm.class);
} catch (IOException e) {
Assert.fail(e.getMessage());
}

IndexingRequestForm indexingRequest = gson.fromJson(inputText, IndexingRequestForm.class);

Assert.assertEquals("update", indexingRequest.getCommand());
Assert.assertEquals("creuser:test", indexingRequest.getQuery());
Expand All @@ -74,9 +93,13 @@ public void indexingUpdateDocumentInc() {
public void indexingDeleteDocumentBulk() {
String inputText = FormattedTextBuilder.getDeleteDocBulkJsonForm();

Gson gson = new Gson();

IndexingRequestForm indexingRequest = gson.fromJson(inputText, IndexingRequestForm.class);
ObjectMapper mapper = new ObjectMapper();
IndexingRequestForm indexingRequest = null;
try {
indexingRequest = mapper.readValue(inputText, IndexingRequestForm.class);
} catch (IOException e) {
Assert.fail(e.getMessage());
}

Assert.assertEquals("delete", indexingRequest.getCommand());
Assert.assertEquals("creuser:test", indexingRequest.getQuery());
Expand All @@ -88,9 +111,13 @@ public void indexingDeleteDocumentBulk() {
public void indexingDeleteDocumentInc() {
String inputText = FormattedTextBuilder.getDeleteDocIncJsonForm();

Gson gson = new Gson();

IndexingRequestForm indexingRequest = gson.fromJson(inputText, IndexingRequestForm.class);
ObjectMapper mapper = new ObjectMapper();
IndexingRequestForm indexingRequest = null;
try {
indexingRequest = mapper.readValue(inputText, IndexingRequestForm.class);
} catch (IOException e) {
Assert.fail(e.getMessage());
}

Assert.assertEquals("delete", indexingRequest.getCommand());
Assert.assertEquals("creuser:test", indexingRequest.getQuery());
Expand Down
16 changes: 12 additions & 4 deletions crescent_utils/build.gradle
Expand Up @@ -6,18 +6,26 @@ version = '0.5-SNAPSHOT'
dependencies {
compile(
[group: 'commons-dbcp', name: 'commons-dbcp', version: '1.4'],
[group: 'com.google.code.gson', name: 'gson', version: '2.2.2'],
[group: 'com.thoughtworks.xstream', name: 'xstream', version: '1.4.3'],
[group: 'commons-pool', name: 'commons-pool', version: '1.6'],
[group: 'org.eclipse.jetty', name: 'jetty-server', version: '9.0.6.v20130930']
[group: 'org.eclipse.jetty', name: 'jetty-server', version: '9.0.6.v20130930'],
[group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.13'],
[group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.2.3'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.2.3'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.2.3']
)

testRuntime(
[group: 'commons-dbcp', name: 'commons-dbcp', version: '1.4'],
[group: 'com.google.code.gson', name: 'gson', version: '2.2.2'],
[group: 'com.thoughtworks.xstream', name: 'xstream', version: '1.4.3'],
[group: 'commons-pool', name: 'commons-pool', version: '1.6'],
[group: 'org.eclipse.jetty', name: 'jetty-server', version: '9.0.6.v20130930']
[group: 'org.eclipse.jetty', name: 'jetty-server', version: '9.0.6.v20130930'],
[group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.13'],
[group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.2.3'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.2.3'],
[group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.2.3']
)

}
Expand Down
Expand Up @@ -21,8 +21,8 @@
import java.util.Map;

import org.apache.commons.dbcp.BasicDataSource;
import org.codehaus.jackson.map.ObjectMapper;

import com.google.gson.Gson;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
Expand Down Expand Up @@ -72,7 +72,7 @@ private void makeFile(String dbName, String xmlLocation) throws SQLException, IO

int rowCount = 0;

Gson gson = new Gson();
ObjectMapper mapper = new ObjectMapper();

while(rs.next()) {
rowCount++;
Expand Down Expand Up @@ -109,7 +109,7 @@ private void makeFile(String dbName, String xmlLocation) throws SQLException, IO
indexingForm.put("indexingType", "bulk");
indexingForm.put("documentList", resultSetMapList);

String jsonForm = gson.toJson(resultSetMapList);
String jsonForm = mapper.writeValueAsString(resultSetMapList);

bw.write(jsonForm);

Expand Down Expand Up @@ -142,7 +142,7 @@ private void makeFile(String dbName, String xmlLocation) throws SQLException, IO

System.out.println("file write start ... [" + targetFile.getName() + "]");

String jsonForm = gson.toJson(resultSetMapList);
String jsonForm = mapper.writeValueAsString(resultSetMapList);

bw.write(jsonForm);

Expand Down

0 comments on commit 5b3bcd1

Please sign in to comment.