-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
125 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
hutool-core/src/main/java/cn/hutool/core/bean/copier/provider/DynaBeanValueProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cn.hutool.core.bean.copier.provider; | ||
|
||
import cn.hutool.core.bean.DynaBean; | ||
import cn.hutool.core.bean.copier.ValueProvider; | ||
import cn.hutool.core.convert.Convert; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* DynaBean值提供者 | ||
* | ||
* @author looly | ||
* @since 5.4.2 | ||
*/ | ||
public class DynaBeanValueProvider implements ValueProvider<String> { | ||
|
||
private final DynaBean dynaBean; | ||
private final boolean ignoreError; | ||
|
||
/** | ||
* 构造 | ||
* | ||
* @param dynaBean DynaBean | ||
* @param ignoreError 是否忽略错误 | ||
*/ | ||
public DynaBeanValueProvider(DynaBean dynaBean, boolean ignoreError) { | ||
this.dynaBean = dynaBean; | ||
this.ignoreError = ignoreError; | ||
} | ||
|
||
@Override | ||
public Object value(String key, Type valueType) { | ||
final Object value = dynaBean.get(key); | ||
return Convert.convertWithCheck(valueType, value, null, this.ignoreError); | ||
} | ||
|
||
@Override | ||
public boolean containsKey(String key) { | ||
return dynaBean.containsProp(key); | ||
} | ||
|
||
} |