Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add testcase #112

Merged
merged 1 commit into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.alibaba.fastjson2.v1issues.issue_3900;

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

import java.util.HashMap;
import java.util.Map;

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

public class Issue3940 {
JSONObject jo;

@BeforeEach
public void init() {
jo = new JSONObject();
}

@Test
public void testInteger() {
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(1, 2);
assertEquals("{\"1\":2}", JSON.toJSONString(map));
}

@Test
public void testFloat() {
Map<Float, Integer> map = new HashMap<Float, Integer>();
map.put(1.23F, 2);
assertEquals("{\"1.23\":2}", JSON.toJSONString(map));
}

@Test
public void testDouble() {
Map<Double, Integer> map = new HashMap<Double, Integer>();
map.put(1.23, 2);
assertEquals("{\"1.23\":2}", JSON.toJSONString(map));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.alibaba.fastjson2.v1issues.issue_3900;

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

import java.util.List;

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

public class Issue3969 {

@Test
public void test_for_issue3969() {
A a = new A();
a.s = "str";
a.c = '0';
String testJson = JSON.toJSONString(a);
assertEquals("{\"c\":\"0\",\"s\":\"str\"}",testJson);
JSONArray jsa = JSON.parseArray("[" + testJson + "]");
List<A> list = jsa.toJavaList(A.class);
assertEquals("[A{s='str', c=0}]",list.toString());
}

@Data
public static class A {

private String s;
private Character c;

public String getS() {
return s;
}
public void setS(String s) {
this.s = s;
}
public Character getC() {
return c;
}
public void setC(Character c) {
this.c = c;
}

@Override
public String toString() {
return "A{" + "s='" + s + '\'' + ", c=" + c + '}';
}
}
}