diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/CodeGenerateEcmaScript.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/CodeGenerateEcmaScript.java index abe1c83aa..7813ddabf 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/CodeGenerateEcmaScript.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/CodeGenerateEcmaScript.java @@ -253,8 +253,10 @@ private String protocol_field_definition(ProtocolRegistration registration) { for (var fieldNote : fieldNotes) { fieldDefinitionBuilder.append(fieldNote).append(LS); } - var fieldTypeValue = esSerializer(fieldRegistration.serializer()).fieldTypeValue(field, fieldRegistration); - fieldDefinitionBuilder.append(StringUtils.format("{} = {}; // {}", fieldName, fieldTypeValue.getValue(), fieldTypeValue.getKey())) + var fieldTypeDefaultValue = esSerializer(fieldRegistration.serializer()).fieldTypeDefaultValue(field, fieldRegistration); + var fieldType = fieldTypeDefaultValue.getKey(); + var fieldDefaultValue = fieldTypeDefaultValue.getValue(); + fieldDefinitionBuilder.append(StringUtils.format("{} = {}; // {}", fieldName, fieldDefaultValue, fieldType)) .append(LS); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsArraySerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsArraySerializer.java index 1cb177709..6722fb485 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsArraySerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsArraySerializer.java @@ -31,7 +31,7 @@ */ public class EsArraySerializer implements IEsSerializer { @Override - public Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration) { + public Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) { var type = StringUtils.format("Array<{}>", CodeGenerateTypeScript.toTsClassName(field.getType().getComponentType().getSimpleName())); return new Pair<>(type, "[]"); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsBoolSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsBoolSerializer.java index 916c6cca2..410c000fb 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsBoolSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsBoolSerializer.java @@ -27,7 +27,7 @@ */ public class EsBoolSerializer implements IEsSerializer { @Override - public Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration) { + public Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) { return new Pair<>("boolean", "false"); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsByteSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsByteSerializer.java index 8b4ecefab..096089e15 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsByteSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsByteSerializer.java @@ -27,7 +27,7 @@ */ public class EsByteSerializer implements IEsSerializer { @Override - public Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration) { + public Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) { return new Pair<>("number", "0"); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsDoubleSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsDoubleSerializer.java index 84a91b370..20708e51a 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsDoubleSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsDoubleSerializer.java @@ -27,7 +27,7 @@ */ public class EsDoubleSerializer implements IEsSerializer { @Override - public Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration) { + public Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) { return new Pair<>("number", "0"); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsFloatSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsFloatSerializer.java index 1776fd1bf..a0c58598b 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsFloatSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsFloatSerializer.java @@ -27,7 +27,7 @@ */ public class EsFloatSerializer implements IEsSerializer { @Override - public Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration) { + public Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) { return new Pair<>("number", "0"); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsIntSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsIntSerializer.java index 85c9268d7..9c2a223e5 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsIntSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsIntSerializer.java @@ -27,7 +27,7 @@ */ public class EsIntSerializer implements IEsSerializer { @Override - public Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration) { + public Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) { return new Pair<>("number", "0"); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsListSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsListSerializer.java index c15ee98ed..346b53ab0 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsListSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsListSerializer.java @@ -31,7 +31,7 @@ */ public class EsListSerializer implements IEsSerializer { @Override - public Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration) { + public Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) { return new Pair<>(CodeGenerateTypeScript.toTsClassName(field.getGenericType().toString()), "[]"); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsLongSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsLongSerializer.java index 3d393e043..c8ae9b6ac 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsLongSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsLongSerializer.java @@ -27,7 +27,7 @@ */ public class EsLongSerializer implements IEsSerializer { @Override - public Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration) { + public Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) { return new Pair<>("number", "0"); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsMapSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsMapSerializer.java index 93dce28aa..37c67c432 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsMapSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsMapSerializer.java @@ -31,7 +31,7 @@ */ public class EsMapSerializer implements IEsSerializer { @Override - public Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration) { + public Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) { return new Pair<>(CodeGenerateTypeScript.toTsClassName(field.getGenericType().toString()), "new Map()"); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsObjectProtocolSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsObjectProtocolSerializer.java index 0166b5122..c50a39a2b 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsObjectProtocolSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsObjectProtocolSerializer.java @@ -29,7 +29,7 @@ */ public class EsObjectProtocolSerializer implements IEsSerializer { @Override - public Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration) { + public Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) { ObjectProtocolField objectProtocolField = (ObjectProtocolField) fieldRegistration; var protocolSimpleName = EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(objectProtocolField.getProtocolId()); var type = StringUtils.format("{} | null", protocolSimpleName); diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsSetSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsSetSerializer.java index 8f81b160b..5a92ec2be 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsSetSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsSetSerializer.java @@ -31,7 +31,7 @@ */ public class EsSetSerializer implements IEsSerializer { @Override - public Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration) { + public Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) { return new Pair<>(CodeGenerateTypeScript.toTsClassName(field.getGenericType().toString()), "new Set()"); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsShortSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsShortSerializer.java index 38ebf910c..bfeb86f8b 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsShortSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsShortSerializer.java @@ -27,7 +27,7 @@ */ public class EsShortSerializer implements IEsSerializer { @Override - public Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration) { + public Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) { return new Pair<>("number", "0"); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsStringSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsStringSerializer.java index 25ac9f11e..8379a8117 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsStringSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/EsStringSerializer.java @@ -27,7 +27,7 @@ */ public class EsStringSerializer implements IEsSerializer { @Override - public Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration) { + public Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) { return new Pair<>("string", "\"\""); } diff --git a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/IEsSerializer.java b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/IEsSerializer.java index f2015b171..49adc824c 100644 --- a/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/IEsSerializer.java +++ b/protocol/src/main/java/com/zfoo/protocol/serializer/ecmascript/IEsSerializer.java @@ -26,7 +26,7 @@ public interface IEsSerializer { /** * 获取属性的类型,默认值 */ - Pair fieldTypeValue(Field field, IFieldRegistration fieldRegistration); + Pair fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration); void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration);