mirror of
https://github.com/alibaba/fastjson.git
synced 2026-10-28 22:04:04 +08:00
support java.sql.Clob
This commit is contained in:
@@ -189,14 +189,14 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>2.0.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-core-lgpl</artifactId>
|
||||
<version>1.9.7</version>
|
||||
<version>1.9.8</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.alibaba.fastjson.serializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Type;
|
||||
import java.sql.Clob;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class ClobSeriliazer implements ObjectSerializer {
|
||||
|
||||
public final static ClobSeriliazer instance = new ClobSeriliazer();
|
||||
|
||||
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
|
||||
try {
|
||||
if (object == null) {
|
||||
serializer.writeNull();
|
||||
return;
|
||||
}
|
||||
|
||||
Clob clob = (Clob) object;
|
||||
Reader reader = clob.getCharacterStream();
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
char[] buf = new char[1024];
|
||||
int len = 0;
|
||||
while ((len = reader.read(buf)) != -1) {
|
||||
writer.write(buf, 0, len);
|
||||
}
|
||||
reader.close();
|
||||
|
||||
String text = writer.toString();
|
||||
serializer.write(text);
|
||||
} catch (SQLException e) {
|
||||
throw new IOException("write clob error", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import java.io.Writer;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
import java.sql.Clob;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@@ -435,6 +436,8 @@ public class JSONSerializer {
|
||||
config.put(clazz, EnumerationSeriliazer.instance);
|
||||
} else if (Calendar.class.isAssignableFrom(clazz)) {
|
||||
config.put(clazz, CalendarSerializer.instance);
|
||||
} else if (Clob.class.isAssignableFrom(clazz)) {
|
||||
config.put(clazz, ClobSeriliazer.instance);
|
||||
} else {
|
||||
boolean isCglibProxy = false;
|
||||
for (Class<?> item : clazz.getInterfaces()) {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.alibaba.json.bvt;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
public class TestDeprecate extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
VO vo = new VO();
|
||||
vo.setId(123);
|
||||
|
||||
String text = JSON.toJSONString(vo);
|
||||
}
|
||||
|
||||
public static class VO {
|
||||
|
||||
private int id;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return
|
||||
*/
|
||||
public int getId2() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getId3() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user