This commit is contained in:
redkale
2024-10-09 23:18:31 +08:00
parent 227e94b546
commit 1bcc35cbcf
2 changed files with 12 additions and 12 deletions

View File

@@ -162,7 +162,7 @@ public class JsonReader extends Reader {
*/
protected char nextChar() {
int p = ++this.position;
if (p >= limit) {
if (p > limit) {
return 0;
}
return this.text[p];

View File

@@ -12,38 +12,38 @@ import org.redkale.convert.json.*;
/** @author zhangjx */
public class TinyTest {
private boolean main;
public static void main(String[] args) throws Throwable {
TinyTest test = new TinyTest();
test.main = true;
test.run();
test.run1();
test.run2();
}
@Test
public void run() throws Exception {
public void run1() throws Exception {
TinyRecord record = new TinyRecord();
record.id = 5;
{
JsonFactory factory = JsonFactory.create().withFeatures(Convert.FEATURE_TINY);
JsonConvert convert = factory.getConvert();
String json = "{\"id\":5}";
if (!main) {
Assertions.assertEquals(json, convert.convertTo(record));
}
Assertions.assertEquals(json, convert.convertTo(record));
System.out.println(convert.convertTo(record));
}
{
JsonFactory factory = JsonFactory.create().withFeatures(0);
JsonConvert convert = factory.getConvert();
String json = "{\"id\":5,\"name\":\"\"}";
if (!main) {
Assertions.assertEquals(json, convert.convertTo(record));
}
Assertions.assertEquals(json, convert.convertTo(record));
System.out.println(convert.convertTo(record));
}
}
@Test
public void run2() throws Exception {
String json = "{\"id\":5,\"name\":\"\", \"status\":2}";
JsonConvert.root().convertFrom(TinyRecord.class, json);
}
public static class TinyRecord {
public String name = "";