The following issues were found
src/test/java/com/alibaba/json/bvt/feature/FeaturesTest3.java
3 issues
Line: 13
public class FeaturesTest3 extends TestCase {
public void test_0() throws Exception {
SerializeConfig config = new SerializeConfig();
config.setAsmEnable(false);
String text = JSON.toJSONString(new Entity(), config);
Assert.assertEquals("{\"value\":0}", text);
Reported by PMD.
Line: 21
Assert.assertEquals("{\"value\":0}", text);
}
public void test_1() throws Exception {
SerializeConfig config = new SerializeConfig();
config.setAsmEnable(true);
String text = JSON.toJSONString(new Entity(), config);
Assert.assertEquals("{\"value\":0}", text);
Reported by PMD.
Line: 31
public static class Entity {
private Integer value;
@JSONField(serialzeFeatures = { SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullNumberAsZero })
public Integer getValue() {
return value;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/kotlin/Issue1569.java
3 issues
Line: 11
import java.io.InputStream;
public class Issue1569 extends TestCase {
public void test_user() throws Exception {
ExtClassLoader classLoader = new ExtClassLoader();
Class clazz = classLoader.loadClass("Issue1569_User");
String json = "{\"loginName\":\"san\",\"userId\":1}";
Object head = JSON.parseObject(json, clazz);
Reported by PMD.
Line: 17
String json = "{\"loginName\":\"san\",\"userId\":1}";
Object head = JSON.parseObject(json, clazz);
assertEquals(json, JSON.toJSONString(head));
}
public static class ExtClassLoader extends ClassLoader {
public ExtClassLoader() throws IOException {
Reported by PMD.
Line: 27
{
byte[] bytes;
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("kotlin/Issue1569_User.clazz");
bytes = IOUtils.toByteArray(is);
is.close();
super.defineClass("Issue1569_User", bytes, 0, bytes.length);
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/feature/FeaturesTest2.java
3 issues
Line: 13
public class FeaturesTest2 extends TestCase {
public void test_0() throws Exception {
SerializeConfig config = new SerializeConfig();
config.setAsmEnable(false);
String text = JSON.toJSONString(new Entity(), config);
Assert.assertEquals("{\"value\":0}", text);
Reported by PMD.
Line: 21
Assert.assertEquals("{\"value\":0}", text);
}
public void test_1() throws Exception {
SerializeConfig config = new SerializeConfig();
config.setAsmEnable(true);
String text = JSON.toJSONString(new Entity(), config);
Assert.assertEquals("{\"value\":0}", text);
Reported by PMD.
Line: 31
private static class Entity {
private Integer value;
@JSONField(serialzeFeatures = { SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullNumberAsZero })
public Integer getValue() {
return value;
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/kotlin/ClassWithPairMixedTypesTest.java
3 issues
Line: 14
* Created by wenshao on 06/08/2017.
*/
public class ClassWithPairMixedTypesTest extends TestCase {
public void test_user() throws Exception {
ExtClassLoader classLoader = new ExtClassLoader();
Class clazz = classLoader.loadClass("ClassWithPairMixedTypes");
String json = "{\"person\":{\"first\":\"wenshao\",\"second\":99}}";
Object obj = JSON.parseObject(json, clazz);
Reported by PMD.
Line: 20
String json = "{\"person\":{\"first\":\"wenshao\",\"second\":99}}";
Object obj = JSON.parseObject(json, clazz);
assertEquals("{\"person\":{\"first\":\"wenshao\",\"second\":99}}", JSON.toJSONString(obj));
}
public static class ExtClassLoader extends ClassLoader {
public ExtClassLoader() throws IOException {
Reported by PMD.
Line: 30
{
byte[] bytes;
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("kotlin/ClassWithPairMixedTypes.clazz");
bytes = IOUtils.toByteArray(is);
is.close();
super.defineClass("ClassWithPairMixedTypes", bytes, 0, bytes.length);
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_1500/Issue1503.java
3 issues
Line: 18
Map<Long, Bean> map = new HashMap<Long, Bean>();
map.put(null, new Bean());
Map<Long, Bean> rmap = (Map<Long, Bean>) JSON.parse(JSON.toJSONString(map, SerializerFeature.WriteClassName), config);
System.out.println(rmap);
}
public static class Bean {
}
Reported by PMD.
Line: 12
import java.util.Map;
public class Issue1503 extends TestCase {
public void test_for_issue() throws Exception {
ParserConfig config = new ParserConfig();
config.setAutoTypeSupport(true);
Map<Long, Bean> map = new HashMap<Long, Bean>();
map.put(null, new Bean());
Map<Long, Bean> rmap = (Map<Long, Bean>) JSON.parse(JSON.toJSONString(map, SerializerFeature.WriteClassName), config);
Reported by PMD.
Line: 12
import java.util.Map;
public class Issue1503 extends TestCase {
public void test_for_issue() throws Exception {
ParserConfig config = new ParserConfig();
config.setAutoTypeSupport(true);
Map<Long, Bean> map = new HashMap<Long, Bean>();
map.put(null, new Bean());
Map<Long, Bean> rmap = (Map<Long, Bean>) JSON.parse(JSON.toJSONString(map, SerializerFeature.WriteClassName), config);
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_1500/Issue1580.java
3 issues
Line: 10
import junit.framework.TestCase;
public class Issue1580 extends TestCase {
public void test_for_issue() throws Exception {
SimplePropertyPreFilter classAFilter = new SimplePropertyPreFilter(Model.class, "code");
SerializeFilter[] filters =new SerializeFilter[]{classAFilter};
Model model = new Model();
model.code = 1001;
Reported by PMD.
Line: 19
model.name = "N1";
String json = JSON.toJSONString(model, filters, SerializerFeature.BeanToArray );
assertEquals("[1001,null]", json);
}
public static class Model {
private int code;
private String name;
Reported by PMD.
Line: 22
assertEquals("[1001,null]", json);
}
public static class Model {
private int code;
private String name;
public int getCode() {
return code;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_1500/Issue1580_private.java
3 issues
Line: 10
import junit.framework.TestCase;
public class Issue1580_private extends TestCase {
public void test_for_issue() throws Exception {
SimplePropertyPreFilter classAFilter = new SimplePropertyPreFilter(Model.class, "code");
SerializeFilter[] filters =new SerializeFilter[]{classAFilter};
Model model = new Model();
model.code = 1001;
Reported by PMD.
Line: 19
model.name = "N1";
String json = JSON.toJSONString(model, filters, SerializerFeature.BeanToArray );
assertEquals("[1001,null]", json);
}
private static class Model {
private int code;
private String name;
Reported by PMD.
Line: 22
assertEquals("[1001,null]", json);
}
private static class Model {
private int code;
private String name;
public int getCode() {
return code;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/joda/JodaTest_4_InstantTest.java
3 issues
Line: 16
vo.setDate(Instant.now());
String text = JSON.toJSONString(vo);
System.out.println(text);
VO vo1 = JSON.parseObject(text, VO.class);
Assert.assertEquals(vo.getDate(), vo1.getDate());
}
Reported by PMD.
Line: 11
public class JodaTest_4_InstantTest extends TestCase {
public void test_for_issue() throws Exception {
VO vo = new VO();
vo.setDate(Instant.now());
String text = JSON.toJSONString(vo);
System.out.println(text);
Reported by PMD.
Line: 20
VO vo1 = JSON.parseObject(text, VO.class);
Assert.assertEquals(vo.getDate(), vo1.getDate());
}
public static class VO {
private Instant date;
Reported by PMD.
src/test/java/com/alibaba/json/bvt/issue_1600/Issue1627.java
3 issues
Line: 8
import junit.framework.TestCase;
public class Issue1627 extends TestCase {
public void test_for_issue() throws Exception {
String a = "{\"101a0.test-b\":\"tt\"}";
Object o = JSON.parse(a);
String s = "101a0.test-b";
assertTrue(JSONPath.contains(o, "$." + escapeString(s)));
}
Reported by PMD.
Line: 12
String a = "{\"101a0.test-b\":\"tt\"}";
Object o = JSON.parse(a);
String s = "101a0.test-b";
assertTrue(JSONPath.contains(o, "$." + escapeString(s)));
}
public static String escapeString(String s) {
StringBuilder buf = new StringBuilder();
Reported by PMD.
Line: 21
for(int i = 0; i < s.length(); ++i) {
char c = s.charAt(i);
if((c < 48 || c > 57) && (c < 65 || c > 90) && (c < 97 || c > 122)) {
buf.append("\\" + c);
} else {
buf.append(c);
}
}
Reported by PMD.
src/test/java/com/alibaba/json/bvt/mixins/MixinAPITest.java
3 issues
Line: 11
public class MixinAPITest extends TestCase {
static class BaseClass {
public int a;
public int b;
public BaseClass() {
}
Reported by PMD.
Line: 12
static class BaseClass {
public int a;
public int b;
public BaseClass() {
}
Reported by PMD.
Line: 32
}
public void test_mixIn_get_methods() throws Exception {
BaseClass base = new BaseClass(1, 2);
JSON.addMixInAnnotations(BaseClass.class, MixIn1.class);
Assert.assertEquals("{\"apple\":1,\"banana\":2}", JSON.toJSONString(base));
Assert.assertTrue(MixIn1.class == JSON.getMixInAnnotations(BaseClass.class));
Reported by PMD.