Skip to content

Commit

Permalink
add testcase for issue #3210
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Jan 1, 2025
1 parent 695f70f commit b53632e
Showing 1 changed file with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.alibaba.fastjson2.issues_3200;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import lombok.Data;
import org.junit.jupiter.api.Test;

import java.nio.charset.StandardCharsets;
import java.util.Date;

import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -17,7 +19,66 @@ public static class Bean {
@Test
public void test() {
String s = "{\"time\":\"2024-12-04T20:43:15.000000999\"}";
Bean bean = JSONObject.parseObject(s, Bean.class);
assertNotNull(bean.time);
{
Bean bean = JSONObject.parseObject(s, Bean.class);
assertNotNull(bean.time);
}
{
Bean bean = JSON.parseObject(s.getBytes(StandardCharsets.UTF_8), Bean.class);
assertNotNull(bean.time);
}
{
Bean bean = JSON.parseObject(s.toCharArray(), Bean.class);
assertNotNull(bean.time);
}
}

@Data
private static class Bean1 {
private Date time;
}

@Test
public void test1() {
String s = "{\"time\":\"2024-12-04T20:43:15.000000999\"}";
{
Bean1 bean = JSONObject.parseObject(s, Bean1.class);
assertNotNull(bean.time);
}
{
byte[] bytes = s.getBytes();
Bean1 bean = JSON.parseObject(bytes, 0, bytes.length, Bean1.class);
assertNotNull(bean.time);
}
{
Bean1 bean = JSON.parseObject(s.toCharArray(), Bean1.class);
assertNotNull(bean.time);
}
}

public static class Bean2 {
public final Date time;

public Bean2(Date time) {
this.time = time;
}
}

@Test
public void test2() {
String s = "{\"time\":\"2024-12-04T20:43:15.000000999\"}";
{
Bean2 bean = JSONObject.parseObject(s, Bean2.class);
assertNotNull(bean.time);
}
{
byte[] bytes = s.getBytes();
Bean2 bean = JSON.parseObject(bytes, 0, bytes.length, Bean2.class);
assertNotNull(bean.time);
}
{
Bean2 bean = JSON.parseObject(s.toCharArray(), Bean2.class);
assertNotNull(bean.time);
}
}
}

0 comments on commit b53632e

Please sign in to comment.