|
|
@@ -8,6 +8,7 @@ import ( |
|
|
jsoniter "github.com/json-iterator/go" |
|
|
jsoniter "github.com/json-iterator/go" |
|
|
"github.com/modern-go/reflect2" |
|
|
"github.com/modern-go/reflect2" |
|
|
"gitlink.org.cn/cloudream/common/pkgs/types" |
|
|
"gitlink.org.cn/cloudream/common/pkgs/types" |
|
|
|
|
|
sertypes "gitlink.org.cn/cloudream/common/utils/serder/types" |
|
|
|
|
|
|
|
|
ref2 "gitlink.org.cn/cloudream/common/utils/reflect2" |
|
|
ref2 "gitlink.org.cn/cloudream/common/utils/reflect2" |
|
|
) |
|
|
) |
|
|
@@ -211,6 +212,12 @@ func (e *InternallyTaggedEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.St |
|
|
val = reflect2.IFaceToEFace(ptr) |
|
|
val = reflect2.IFaceToEFace(ptr) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if val != nil { |
|
|
|
|
|
if on, ok := val.(sertypes.OnUnionSerializing); ok { |
|
|
|
|
|
on.OnUnionSerializing() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 可以考虑检查一下Type字段有没有赋值,没有赋值则将其赋值为union Tag指定的值 |
|
|
// 可以考虑检查一下Type字段有没有赋值,没有赋值则将其赋值为union Tag指定的值 |
|
|
stream.WriteVal(val) |
|
|
stream.WriteVal(val) |
|
|
} |
|
|
} |
|
|
@@ -292,6 +299,10 @@ func (e *ExternallyTaggedEncoder) Encode(ptr unsafe.Pointer, stream *jsoniter.St |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if on, ok := val.(sertypes.OnUnionSerializing); ok { |
|
|
|
|
|
on.OnUnionSerializing() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
stream.WriteObjectStart() |
|
|
stream.WriteObjectStart() |
|
|
valType := ref2.TypeOfValue(val) |
|
|
valType := ref2.TypeOfValue(val) |
|
|
if !e.union.Union.Include(valType) { |
|
|
if !e.union.Union.Include(valType) { |
|
|
|