Skip to content

Commit

Permalink
support Clickhouse UnsignedLong, for issue #2952
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Sep 15, 2024
1 parent 30b4e64 commit 45b54ec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import com.alibaba.fastjson2.modules.ObjectCodecProvider;
import com.alibaba.fastjson2.modules.ObjectWriterAnnotationProcessor;
import com.alibaba.fastjson2.modules.ObjectWriterModule;
import com.alibaba.fastjson2.util.BeanUtils;
import com.alibaba.fastjson2.util.GuavaSupport;
import com.alibaba.fastjson2.util.JDKUtils;
import com.alibaba.fastjson2.util.TypeUtils;
import com.alibaba.fastjson2.util.*;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -447,6 +444,8 @@ private ObjectWriter getObjectWriterInternal(Type objectType, Class objectClass,
case "android.net.Uri$StringUri":
objectWriter = ObjectWriterImplToString.INSTANCE;
break;
case "com.clickhouse.data.value.UnsignedLong":
objectWriter = new ObjectWriterImplToString(true);
default:
break;
}
Expand Down
7 changes: 7 additions & 0 deletions extension/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@
<version>${fastjson1x.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.6.5</version>
<classifier>http</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.alibaba.fastjson2.issues;

import com.alibaba.fastjson2.JSON;
import com.clickhouse.data.value.UnsignedLong;
import org.junit.jupiter.api.Test;

import java.math.BigInteger;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue2958 {
@Test
public void test() throws Exception {
String str = "9223372036854775808";
UnsignedLong unsignedLong = UnsignedLong.valueOf(new BigInteger(str));
String json = JSON.toJSONString(unsignedLong);
assertEquals(str, json);
}
}

0 comments on commit 45b54ec

Please sign in to comment.