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。