Skip to content

Commit

Permalink
fix setBeanCopyConfig bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
yangtu222 committed Aug 11, 2018
1 parent 4563236 commit 88b7951
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This BeanUtils library is a Java bean copy utility with powerful functionality a
<dependency>
<groupId>com.github.yangtu222</groupId>
<artifactId>BeanUtils</artifactId>
<version>1.0.8</version>
<version>1.0.9</version>
</dependency>
~~~

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.github.yangtu222</groupId>
<artifactId>BeanUtils</artifactId>
<name>BeanUtils</name>
<version>1.0.8</version>
<version>1.0.9</version>
<description>BeanUtils library is a Java bean copy utility with powerful functionality and high performance.</description>
<url>https://github.com/yangtu222/BeanUtils</url>

Expand All @@ -27,7 +27,7 @@
<connection>scm:git:https://github.com/yangtu222/BeanUtils.git</connection>
<developerConnection>scm:git:https://github.com/yangtu222/BeanUtils.git</developerConnection>
<url>https://github.com/yangtu222/BeanUtils.git</url>
<tag>v1.0.8</tag>
<tag>v1.0.9</tag>
</scm>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ public static void setBeanCopyConfig(BeanCopyConfig beanCopyConfig) {
if( beanCopyConfig == null )
beanCopyConfig = new BeanCopyConfig();
BeanCopyCache.beanCopyConfig = beanCopyConfig;
if( beanCopyFactory!= null && !beanCopyFactory.getClass().equals(beanCopyConfig.getBeanCopyFactory() ) )
beanCopyCacheMap.clear();
beanCopyFactory = null;
synchronized (BeanCopyCache.class) {
if( beanCopyFactory != null && !beanCopyFactory.equals(beanCopyConfig.getBeanCopyFactory() ) )
beanCopyCacheMap.clear();
beanCopyFactory = null;
}
}

public static BeanCopier getBeanCopy(Class<?> sourceClass, Class<?> targetClass, Class<?> optionClass) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/com/tuyang/test/testBasic/Test01.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.Test;

import com.tuyang.beanutils.BeanCopyUtils;
import com.tuyang.beanutils.config.BeanCopyConfig;

public class Test01 {

Expand Down Expand Up @@ -37,6 +38,12 @@ public void testBasic() {
assertEquals( fromBean.getBeanDouble(), toBean.getBeanDouble(), 0 );
assertEquals( fromBean.getBeanString(), toBean.getBeanString() );
assertEquals(fromBean.getmId(), toBean.getmId());

BeanCopyConfig.setBeanCopyConfig(null);

ToBean toBean2 = BeanCopyUtils.copyBean(fromBean, ToBean.class);
assertEquals(fromBean.isBeanBool(), toBean2.isBeanBool() );

}
}

0 comments on commit 88b7951

Please sign in to comment.