首页 > 编程知识 正文

fastjson jackson,java中的泛型怎么用

时间:2023-05-05 00:32:09 阅读:145964 作者:1286

forjsonmappingiusethefollowingmethod :

publicstatictmapjsontoobject (string JSON,T dtoClass ) throws Exception {

returnmapper.readvalue(JSON,new TypeReference ) )

);

}

和用户到looks like this :

@ jsonignoreproperties (ignore unknown=true )

公共类用户到{

@JSONproperty(items ) )。

私有列表用户列表;

公共列表获取用户列表()。

返回用户列表;

}

公共语音用户列表(列表用户列表) )

this.userList=userList;

}

}

iwanttoimprovethismethodofmappingwithoutbeingattachedtoauserdtoclass,和复制it with a generic。

is it可销售? And How?

解决方案

watithinkyouneedisjavatype : youcanbuildinstancesdynamicallybyusingtypefactory.yougetaninstanceoftypefactoryviaobjectmapiobjectm oconstructjavatypeinstancesfromsimpleclassaswellastypereference。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。