Skip to content
Permalink
Browse files
test: add json serialize test
  • Loading branch information
DLive committed May 12, 2019
1 parent 7fac8e8 commit 91f9c91639c2e6d9de0ff29ebfab52e78f3260aa
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
@@ -20,7 +20,7 @@
{zookeeper_list,[{"127.0.0.1",2181}]},
{application,<<"testdubboerl">>},
{registry,true},
{protocol,hessian},
{protocol,json},
{port,20881},
{consumer,[
{<<"com.ifcoder.demo.facade.User">>,[]}
@@ -13,7 +13,7 @@
-include("dubbo.hrl").

%% API
-export([java_to_native/2,pre_process_typedef/3,response_to_native/1,classobj_to_native/2]).
-export([java_to_native/2,pre_process_typedef/3,response_to_native/1,classobj_to_native/2,jsonobj_to_native/3]).


response_to_native(Response)->
@@ -66,4 +66,28 @@ pre_process_typedef(NativeType,ForeignType,FieldsNames)->
%% Type2=type_decoding:hash_store(Type),
type_register:regiest_foreign_native(Type),
logger:debug("pre_process_typedef ~p,~p",[NativeType,ForeignType]),
ok.
ok.


jsonobj_to_native(Type,JsonObj,State)->
ClassName = java_desc_name_to_dot(Type),
%% todo need recursion transfer
case type_register:lookup_foreign_type(ClassName) of
undefined ->
JsonObj;
#type_def{fieldnames = Fields,native_type = NativeType} ->
logger:debug("jsonobj_to_native ~p ~p ~p",[ClassName,Fields,JsonObj]),
NativeData = [ maps:get(atom_to_binary(Key,utf8),JsonObj,undefined) || Key <- Fields],
list_to_tuple( [NativeType] ++ NativeData)
end.



java_desc_name_to_dot(DescName) ->
case DescName of
<<$L,ClassName/binary>> ->
binary:replace(ClassName,<<"/">>,<<".">>,[global]);
_ ->
DescName
end.

@@ -15,7 +15,7 @@
-include_lib("dubboerl/include/hessian.hrl").
-include_lib("dubboerl/include/dubbo.hrl").
%% API
-export([getUserInfo/1,queryUserList/1,genUserId/0]).
-export([getUserInfo/1,queryUserList/1,genUserId/0,queryUserInfo/1]).

genUserId()->
"newid".
@@ -31,4 +31,9 @@ queryUserList(Args)->
Res = #userRes{
userlist = List
},
Res.
Res.


queryUserInfo(Arg0)->
io:format(user,"do invoker queryUserInfo ~p",[Arg0]),
#userInfo{userName = "uuname",userAge = 10,userId = "44"}.
@@ -9,7 +9,7 @@
-include("dubbo_service.hrl").



-export([test/0]).

%% API
-export([
@@ -160,3 +160,6 @@ queryUserList(Arg0, RequestOption)->
Request = dubbo_adapter:reference(Data),
dubbo_invoker:invoke_request(?CURRENT_CLASS_NAME,Request,RequestOption).


test()->
queryUserInfo(#userInfoRequest{username = "name",requestId = "111"},#{sync=> true}).

0 comments on commit 91f9c91

Please sign in to comment.