Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
gostnops
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
gostnops
Commits
b3e5bc76
Commit
b3e5bc76
authored
Dec 01, 2020
by
李志信
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: remove hessian rely
parent
a3f35263
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
27 deletions
+40
-27
go.mod
go.mod
+0
-1
parser.go
jparser/parser.go
+40
-26
No files found.
go.mod
View file @
b3e5bc76
module github.com/dubbogo/gost
require (
github.com/apache/dubbo-go-hessian2 v1.8.0-rc1
github.com/buger/jsonparser v1.0.0
github.com/davecgh/go-spew v1.1.1
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
...
...
jparser/parser.go
View file @
b3e5bc76
...
...
@@ -26,30 +26,36 @@ import (
"strings"
"time"
hessian2
"github.com/apache/dubbo-go-hessian2"
"github.com/buger/jsonparser"
)
type
HessianRegisterPair
struct
{
JavaClassName
string
Obj
interface
{}
}
type
jsonStructParser
struct
{
structFields
[]
reflect
.
StructField
valueMap
map
[
string
]
string
subObjValueMap
map
[
string
]
reflect
.
Value
structFields
[]
reflect
.
StructField
hessianRegisterPair
[]
HessianRegisterPair
valueMap
map
[
string
]
string
subObjValueMap
map
[
string
]
reflect
.
Value
}
func
newJSONStructParser
()
*
jsonStructParser
{
return
&
jsonStructParser
{
structFields
:
make
([]
reflect
.
StructField
,
0
),
valueMap
:
make
(
map
[
string
]
string
),
subObjValueMap
:
make
(
map
[
string
]
reflect
.
Value
),
structFields
:
make
([]
reflect
.
StructField
,
0
),
valueMap
:
make
(
map
[
string
]
string
),
hessianRegisterPair
:
make
([]
HessianRegisterPair
,
0
),
subObjValueMap
:
make
(
map
[
string
]
reflect
.
Value
),
}
}
// J
son
File2Interface parse json @filePath to interface
func
J
sonFile2Interface
(
filePath
string
)
(
interface
{},
error
)
{
// J
SON
File2Interface parse json @filePath to interface
func
J
SONFile2Interface
(
filePath
string
)
([]
HessianRegisterPair
,
interface
{},
error
)
{
defer
func
()
{
defaultJSONStructParser
=
newJSONStructParser
()
}()
return
defaultJSONStructParser
.
JSON
FilePath2Struct
(
filePath
)
return
defaultJSONStructParser
.
json
FilePath2Struct
(
filePath
)
}
func
init
()
{
...
...
@@ -58,11 +64,12 @@ func init() {
var
defaultJSONStructParser
*
jsonStructParser
// RemoveTargetNameField remove target file in @v
func
RemoveTargetNameField
(
v
interface
{},
targetName
string
)
interface
{}
{
defer
func
()
{
defaultJSONStructParser
=
newJSONStructParser
()
}()
return
defaultJSONStructParser
.
R
emoveTargetNameField
(
v
,
targetName
)
return
defaultJSONStructParser
.
r
emoveTargetNameField
(
v
,
targetName
)
}
func
(
jsp
*
jsonStructParser
)
cb
(
key
[]
byte
,
value
[]
byte
,
dataType
jsonparser
.
ValueType
,
offset
int
)
error
{
...
...
@@ -70,20 +77,27 @@ func (jsp *jsonStructParser) cb(key []byte, value []byte, dataType jsonparser.Va
case
jsonparser
.
Object
:
// 嵌套子结构
newParser
:=
newJSONStructParser
()
subObj
:=
newParser
.
json2Struct
(
value
)
hessian2
.
RegisterPOJOMapping
(
getJavaClassName
(
subObj
),
subObj
)
jsp
.
structFields
=
append
(
jsp
.
structFields
,
reflect
.
StructField
{
Name
:
string
(
key
),
Type
:
reflect
.
TypeOf
(
subObj
),
jsp
.
hessianRegisterPair
=
append
(
jsp
.
hessianRegisterPair
,
HessianRegisterPair
{
JavaClassName
:
getJavaClassName
(
subObj
),
Obj
:
subObj
,
})
jsp
.
subObjValueMap
[
string
(
key
)]
=
reflect
.
ValueOf
(
subObj
)
case
jsonparser
.
Array
:
//数组结构
newParser
:=
newJSONStructParser
()
subObj
:=
newParser
.
json2Struct
(
value
)
hessian2
.
RegisterPOJOMapping
(
getJavaClassName
(
subObj
),
subObj
)
// TODO 目前存在问题
jsp
.
structFields
=
append
(
jsp
.
structFields
,
reflect
.
StructField
{
Name
:
string
(
key
),
Type
:
reflect
.
TypeOf
(
subObj
),
})
jsp
.
subObjValueMap
[
string
(
key
)]
=
reflect
.
ValueOf
(
subObj
)
case
jsonparser
.
Array
:
//数组结构 TODO slice解析
//newParser := newJSONStructParser()
//subObj := newParser.json2Struct(value)
//jsp.hessianRegisterPair = append(jsp.hessianRegisterPair, HessianRegisterPair{
// JavaClassName: getJavaClassName(subObj),
// Obj: subObj,
//})
//jsp.structFields = append(jsp.structFields, reflect.StructField{
// Name: string(key),
// Type: reflect.TypeOf(subObj),
//})
case
jsonparser
.
String
:
// 正常结构
// "type@value"
...
...
@@ -168,17 +182,17 @@ func (jsp *jsonStructParser) json2Struct(jsonData []byte) interface{} {
return
s
}
//
JSON
FilePath2Struct read file from @filePath and parse data to interface
func
(
jsp
*
jsonStructParser
)
JSONFilePath2Struct
(
filePath
string
)
(
interface
{},
error
)
{
//
json
FilePath2Struct read file from @filePath and parse data to interface
func
(
jsp
*
jsonStructParser
)
jsonFilePath2Struct
(
filePath
string
)
([]
HessianRegisterPair
,
interface
{},
error
)
{
jsonData
,
err
:=
ioutil
.
ReadFile
(
filePath
)
if
err
!=
nil
{
return
nil
,
err
return
[]
HessianRegisterPair
{},
nil
,
err
}
return
jsp
.
json2Struct
(
jsonData
),
nil
return
jsp
.
hessianRegisterPair
,
jsp
.
json2Struct
(
jsonData
),
nil
}
//
R
emoveTargetNameField remove origin interface @v's target field by @targetName
func
(
jsp
*
jsonStructParser
)
R
emoveTargetNameField
(
v
interface
{},
targetName
string
)
interface
{}
{
//
r
emoveTargetNameField remove origin interface @v's target field by @targetName
func
(
jsp
*
jsonStructParser
)
r
emoveTargetNameField
(
v
interface
{},
targetName
string
)
interface
{}
{
typ
:=
reflect
.
TypeOf
(
v
)
.
Elem
()
val
:=
reflect
.
ValueOf
(
v
)
.
Elem
()
nums
:=
val
.
NumField
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment