diff --git a/pom.xml b/pom.xml
index a963000..8125ab1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
io.github.yezhihao
protostar
- 1.0.5.RELEASE
+ 2.0.0.RELEASE
jar
Protostar
@@ -50,13 +50,13 @@
org.slf4j
slf4j-simple
- 1.7.30
+ 1.7.31
test
org.slf4j
slf4j-api
- 1.7.30
+ 1.7.31
provided
diff --git a/src/main/java/io/github/yezhihao/protostar/DefaultLoadStrategy.java b/src/main/java/io/github/yezhihao/protostar/DefaultLoadStrategy.java
index e77d018..ece7b6e 100644
--- a/src/main/java/io/github/yezhihao/protostar/DefaultLoadStrategy.java
+++ b/src/main/java/io/github/yezhihao/protostar/DefaultLoadStrategy.java
@@ -1,9 +1,9 @@
package io.github.yezhihao.protostar;
import io.github.yezhihao.protostar.annotation.Message;
+import io.github.yezhihao.protostar.schema.RuntimeSchema;
import io.github.yezhihao.protostar.util.ClassUtils;
-import java.beans.Introspector;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -14,7 +14,7 @@ import java.util.Map;
*/
public class DefaultLoadStrategy extends LoadStrategy {
- private Map>> typeClassMapping = new HashMap(140);
+ private Map>> typeClassMapping = new HashMap(140);
public DefaultLoadStrategy() {
}
@@ -26,33 +26,32 @@ public class DefaultLoadStrategy extends LoadStrategy {
if (message != null) {
int[] values = message.value();
for (int typeId : values)
- loadSchema(typeClassMapping, typeId, type);
+ loadRuntimeSchema(typeClassMapping, typeId, type);
}
}
- Introspector.flushCaches();
}
@Override
- public Schema getSchema(Class typeClass, Integer version) {
- Map> schemas = typeClassMapping.get(typeClass.getName());
+ public RuntimeSchema getRuntimeSchema(Class typeClass, Integer version) {
+ Map> schemas = typeClassMapping.get(typeClass.getName());
if (schemas == null) {
- schemas = loadSchema(typeClassMapping, typeClass);
+ schemas = loadRuntimeSchema(typeClassMapping, typeClass);
}
if (schemas == null) return null;
- return (Schema) schemas.get(version);
+ return (RuntimeSchema) schemas.get(version);
}
@Override
- public Map> getSchema(Class typeClass) {
- Map> schemas = typeClassMapping.get(typeClass.getName());
+ public Map> getRuntimeSchema(Class typeClass) {
+ Map> schemas = typeClassMapping.get(typeClass.getName());
if (schemas == null) {
- schemas = loadSchema(typeClassMapping, typeClass);
+ schemas = loadRuntimeSchema(typeClassMapping, typeClass);
}
if (schemas == null) return null;
- HashMap> result = new HashMap<>(schemas.size());
- for (Map.Entry> entry : schemas.entrySet()) {
- result.put(entry.getKey(), (Schema) entry.getValue());
+ HashMap> result = new HashMap<>(schemas.size());
+ for (Map.Entry> entry : schemas.entrySet()) {
+ result.put(entry.getKey(), (RuntimeSchema) entry.getValue());
}
return result;
}
diff --git a/src/main/java/io/github/yezhihao/protostar/FieldFactory.java b/src/main/java/io/github/yezhihao/protostar/FieldFactory.java
index 00cc2f8..5f7a260 100644
--- a/src/main/java/io/github/yezhihao/protostar/FieldFactory.java
+++ b/src/main/java/io/github/yezhihao/protostar/FieldFactory.java
@@ -10,7 +10,6 @@ import io.github.yezhihao.protostar.schema.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.beans.PropertyDescriptor;
import java.nio.ByteBuffer;
import java.time.LocalDateTime;
@@ -23,13 +22,13 @@ public abstract class FieldFactory {
protected static Logger log = LoggerFactory.getLogger(FieldFactory.class.getSimpleName());
public static boolean EXPLAIN = false;
- public static BasicField create(Field field, PropertyDescriptor property) {
- return create(field, property, null);
+ public static BasicField create(Field field, java.lang.reflect.Field f) {
+ return create(field, f, null);
}
- public static BasicField create(Field field, PropertyDescriptor property, Schema schema) {
+ public static BasicField create(Field field, java.lang.reflect.Field f, Schema schema) {
DataType dataType = field.type();
- Class> typeClass = property.getPropertyType();
+ Class> typeClass = f.getType();
Schema fieldSchema;
switch (dataType) {
@@ -63,7 +62,7 @@ public abstract class FieldFactory {
if (schema != null) {
fieldSchema = ObjectSchema.getInstance(schema);
} else {
- Convert convert = property.getReadMethod().getAnnotation(Convert.class);
+ Convert convert = f.getAnnotation(Convert.class);
fieldSchema = ConvertSchema.getInstance(convert.converter());
}
break;
@@ -71,7 +70,7 @@ public abstract class FieldFactory {
fieldSchema = CollectionSchema.getInstance(schema);
break;
case MAP:
- Convert convert = property.getReadMethod().getAnnotation(Convert.class);
+ Convert convert = f.getAnnotation(Convert.class);
fieldSchema = ConvertSchema.getInstance(convert.converter());
break;
default:
@@ -82,19 +81,19 @@ public abstract class FieldFactory {
BasicField result;
if (EXPLAIN) {
if (field.lengthSize() > 0) {
- result = new DynamicLengthField.Logger(field, property, fieldSchema);
+ result = new DynamicLengthField.Logger(field, f, fieldSchema);
} else if (field.length() > 0) {
- result = new FixedLengthField.Logger(field, property, fieldSchema);
+ result = new FixedLengthField.Logger(field, f, fieldSchema);
} else {
- result = new FixedField.Logger(field, property, fieldSchema);
+ result = new FixedField.Logger(field, f, fieldSchema);
}
} else {
if (field.lengthSize() > 0) {
- result = new DynamicLengthField(field, property, fieldSchema);
+ result = new DynamicLengthField(field, f, fieldSchema);
} else if (field.length() > 0) {
- result = new FixedLengthField(field, property, fieldSchema);
+ result = new FixedLengthField(field, f, fieldSchema);
} else {
- result = new FixedField(field, property, fieldSchema);
+ result = new FixedField(field, f, fieldSchema);
}
}
return result;
diff --git a/src/main/java/io/github/yezhihao/protostar/IdStrategy.java b/src/main/java/io/github/yezhihao/protostar/IdStrategy.java
index a82a41d..e6bfdd8 100644
--- a/src/main/java/io/github/yezhihao/protostar/IdStrategy.java
+++ b/src/main/java/io/github/yezhihao/protostar/IdStrategy.java
@@ -5,11 +5,6 @@ import io.github.yezhihao.protostar.field.BasicField;
import io.github.yezhihao.protostar.schema.RuntimeSchema;
import io.netty.buffer.ByteBuf;
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.*;
@@ -54,11 +49,11 @@ public abstract class IdStrategy {
if (schema != null)
return (Schema) schema;
- List properties = findFieldProperties(typeClass);
- if (properties.isEmpty())
+ List fs = findFields(typeClass);
+ if (fs.isEmpty())
return null;
- List fieldList = findFields(root, properties);
+ List fieldList = findFields(root, fs);
BasicField[] fields = fieldList.toArray(new BasicField[fieldList.size()]);
Arrays.sort(fields);
@@ -67,57 +62,44 @@ public abstract class IdStrategy {
return (Schema) schema;
}
- protected static List findFieldProperties(Class typeClass) {
- BeanInfo beanInfo;
- try {
- beanInfo = Introspector.getBeanInfo(typeClass);
- } catch (IntrospectionException e) {
- throw new RuntimeException(e);
- }
- PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors();
- List result = new ArrayList<>(properties.length);
+ protected static List findFields(Class typeClass) {
+ java.lang.reflect.Field[] fields = typeClass.getDeclaredFields();
+ List result = new ArrayList<>(fields.length);
- for (PropertyDescriptor property : properties) {
- Method readMethod = property.getReadMethod();
-
- if (readMethod != null) {
- if (readMethod.isAnnotationPresent(Field.class)) {
- result.add(property);
- }
+ for (java.lang.reflect.Field f : fields) {
+ if (f.isAnnotationPresent(Field.class)) {
+ result.add(f);
}
}
return result;
}
- protected static List findFields(Map