java - Is there a way to map a Set to a List with BeanUtils.copyProperties? -
I'm using BeanUtils.copyProperties
to convert two beans
Beanutils. Copproperties (organization, deto organization);
I have to do a list
in one bean and set one to
in the other.
First Been:
Public Category Form {Private Set & lt; Organization & gt; Organization; }
Second bean:
Public final category DTOForm {Private list & lt; DTOOrganization & gt; Organization; }
The result is an exception as described here:
Is it possible to optimize BeanUtils.copyProperties
?
You can solve it by using custom converters. The main idea is that ListEntity, which has / Code> Property (as far as I do not ignore the setters and gates): Simple test class to work: The main idea of this code sniper: We register converter for all the destination class As a result, both set <
list
Public Class List {Private list & lt; Integer & gt; Col = new arreelist & lt; & Gt; (); Public listing & lt; Integer & gt; GetCol () {Return Colonel; } Public Zero Set Call (list & gt; integer & gt; col) {this.col = col; Set}} SetEntity, which has
set
property:
public class SetEntity {private set} & Lt; Integer & gt; Col = new hashset & lt; & Gt; (); Public set & lt; Integer & gt; GetCol () {Return Colonel; } Public Zero Set Call (set & lt; integer & gt; col) {this.col = col; }}
public class exam {public static zero major (string. Ars.) Throws InvocationTargetException, IllegalAccessException {SetEntity se = New SetEntity (); Se.getCol () add (1). Se.getCol () add (2). ListEntity le = New ListEntity (); ConvertUtility Register (new converter) {@ Override public & lt; T & gt; T convert (class
List
properties, this is some object o
To list
. Assuming that o
is a collection, we repeat it and then return the newly created list. 1
and 2
in le
If you do not need this converter anymore, You can unregister by using
Comments
Post a Comment