mirror of https://github.com/alibaba/fastjson2.git
codegen support char field
This commit is contained in:
parent
6c977ec759
commit
0c7d40d9a1
|
|
@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class BasicTypeTest {
|
public class BasicTypeTest {
|
||||||
// @Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
Bean bean = new Bean();
|
Bean bean = new Bean();
|
||||||
bean.f0 = 100;
|
bean.f0 = 100;
|
||||||
|
|
@ -31,6 +31,7 @@ public class BasicTypeTest {
|
||||||
assertEquals(str, str2);
|
assertEquals(str, str2);
|
||||||
|
|
||||||
byte[] jsonb = JSONB.toBytes(bean);
|
byte[] jsonb = JSONB.toBytes(bean);
|
||||||
|
System.out.println(JSONB.toJSONString(jsonb));
|
||||||
Bean bean3 = JSONB.parseObject(jsonb, Bean.class);
|
Bean bean3 = JSONB.parseObject(jsonb, Bean.class);
|
||||||
assertEquals(str, JSON.toJSONString(bean3));
|
assertEquals(str, JSON.toJSONString(bean3));
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +49,7 @@ public class BasicTypeTest {
|
||||||
public String f8;
|
public String f8;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
public void test1() {
|
public void test1() {
|
||||||
Bean1 bean = new Bean1();
|
Bean1 bean = new Bean1();
|
||||||
bean.f0 = 100;
|
bean.f0 = 100;
|
||||||
|
|
|
||||||
|
|
@ -345,6 +345,7 @@ public class JSONCompiledAnnotationProcessor
|
||||||
boolean isMethodReference) {
|
boolean isMethodReference) {
|
||||||
String type = attributeInfo.type.toString();
|
String type = attributeInfo.type.toString();
|
||||||
if ("boolean".equals(type)
|
if ("boolean".equals(type)
|
||||||
|
|| "char".equals(type)
|
||||||
|| "byte".equals(type)
|
|| "byte".equals(type)
|
||||||
|| "short".equals(type)
|
|| "short".equals(type)
|
||||||
|| "int".equals(type)
|
|| "int".equals(type)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package com.alibaba.fastjson2.internal.processor;
|
package com.alibaba.fastjson2.internal.processor;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.PropertyNamingStrategy;
|
import com.alibaba.fastjson2.PropertyNamingStrategy;
|
||||||
import com.alibaba.fastjson2.annotation.JSONCompiled;
|
|
||||||
import com.alibaba.fastjson2.annotation.JSONField;
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
import com.alibaba.fastjson2.annotation.JSONType;
|
import com.alibaba.fastjson2.annotation.JSONType;
|
||||||
|
|
||||||
|
|
@ -10,7 +9,7 @@ import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@JSONType(naming = PropertyNamingStrategy.PascalCase)
|
@JSONType(naming = PropertyNamingStrategy.PascalCase)
|
||||||
@JSONCompiled
|
//@com.alibaba.fastjson2.annotation.JSONCompiled
|
||||||
public class Bean {
|
public class Bean {
|
||||||
@JSONField(name = "uid")
|
@JSONField(name = "uid")
|
||||||
public int id;
|
public int id;
|
||||||
|
|
|
||||||
|
|
@ -1036,6 +1036,10 @@ public class ObjectWriterCreator {
|
||||||
return new FieldWriterDoubleValueFunc(fieldName, 0, 0, null, null, null, null, function);
|
return new FieldWriterDoubleValueFunc(fieldName, 0, 0, null, null, null, null, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> FieldWriter createFieldWriter(String fieldName, ToCharFunction<T> function) {
|
||||||
|
return new FieldWriterCharValFunc(fieldName, 0, 0, null, null, null, null, function);
|
||||||
|
}
|
||||||
|
|
||||||
public <T> FieldWriter createFieldWriter(String fieldName, Predicate<T> function) {
|
public <T> FieldWriter createFieldWriter(String fieldName, Predicate<T> function) {
|
||||||
return new FieldWriterBoolValFunc(fieldName, 0, 0, null, null, null, null, function);
|
return new FieldWriterBoolValFunc(fieldName, 0, 0, null, null, null, null, function);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.alibaba.fastjson2.writer;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.codec.FieldInfo;
|
import com.alibaba.fastjson2.codec.FieldInfo;
|
||||||
import com.alibaba.fastjson2.function.ToByteFunction;
|
import com.alibaba.fastjson2.function.ToByteFunction;
|
||||||
|
import com.alibaba.fastjson2.function.ToCharFunction;
|
||||||
import com.alibaba.fastjson2.function.ToFloatFunction;
|
import com.alibaba.fastjson2.function.ToFloatFunction;
|
||||||
import com.alibaba.fastjson2.function.ToShortFunction;
|
import com.alibaba.fastjson2.function.ToShortFunction;
|
||||||
import com.alibaba.fastjson2.util.ParameterizedTypeImpl;
|
import com.alibaba.fastjson2.util.ParameterizedTypeImpl;
|
||||||
|
|
@ -163,6 +164,10 @@ public class ObjectWriters {
|
||||||
return INSTANCE.createFieldWriter(fieldName, function);
|
return INSTANCE.createFieldWriter(fieldName, function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T> FieldWriter fieldWriter(String fieldName, ToCharFunction<T> function) {
|
||||||
|
return INSTANCE.createFieldWriter(fieldName, function);
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> FieldWriter fieldWriter(String fieldName, Predicate<T> function) {
|
public static <T> FieldWriter fieldWriter(String fieldName, Predicate<T> function) {
|
||||||
return INSTANCE.createFieldWriter(fieldName, function);
|
return INSTANCE.createFieldWriter(fieldName, function);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue