Provide an additional toolkit library for spring framework.
Notes: All the testing features are moved to https://github.com/ahunigel/spring-test-toolkit
YamlPropertySourceFactory
- Spring
@PropertySource
does not supportyml
andyaml
by default, this factory help load yaml files
- Spring
ReversibleConverter<A, B>
- reverse converter with
.reverse()
method - functional converter, used for java
stream
mapping - instance of spring converter
- reverse converter with
BeanUtilEx
- Enhance the spring
BeanUtils
, providePredicate
as name or value filters for copy properties
- Enhance the spring
JsonPropertySourceFactory
- Spring
@PropertySource
does not supportjson
by default, this factory help load json files
- Spring
CollectionUtilEx
- concat(c1, c2, ..., cN)
- nullToEmpty(Collection c)
- isNotEmpty(Collection c)
DialectUtil
- getInExpressionCountLimit(EntityManager entityManager)
AssertEx
- supported(boolean expression, String message)
- hasPermission(boolean expression, String message)
BeanConvertUtils
- support convert
S
type toT
type
- support convert
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.ahunigel:spring-toolkit:{version}'
}
Refer to https://jitpack.io/#ahunigel/spring-toolkit for details.
@PropertySource(value = {"classpath:custom.yml", "classpath:custom2.yml"}, factory = YamlPropertySourceFactory.class)
public class FooApplication {
}
public class FooConverter extends ReversibleConverter<Foo, Boo> {
}
public class FooTest {
@Test
public void testFoo() {
assertThat(converter.convert(foo)).isNotNull().isEqualTo(boo);
assertThat(converter.doForward(foo)).isNotNull().isEqualTo(boo);
assertThat(converter.doBackward(boo)).isNotNull().isEqualTo(foo);
assertThat(converter.convert(foo, new Boo())).isNotNull().isEqualTo(boo);
assertThat(converter.reverseConvert(boo, new Foo())).isNotNull().isEqualTo(foo);
assertThat(converter.reverse().convert(boo)).isNotNull().isEqualTo(foo);
assertThat(converter.reverse().reverse().convert(foo)).isNotNull().isEqualTo(boo);
List<Boo> booList = Arrays.asList(foo).stream().map(converter).collect(Collectors.toList());
booList.stream().map(converter.reverse()).forEach(f -> assertThat(f).isNotNull().isEqualTo(foo));
booList.stream().map(converter.reverse().reversible().reverse()).forEach(f -> assertThat(f).isNotNull().isEqualTo(foo));
Iterable<Boo> booList = converter.convertAll(Arrays.asList(foo));
booList.forEach(b -> assertThat(b).isNotNull().isEqualTo(boo));
converter.reverse().convertAll(booList).forEach(f -> assertThat(f).isNotNull().isEqualTo(foo));
}
}
public class FooUtil {
public static void copy(Foo foo, Foo target) {
BeanUtilEx.copyProperties(foo, target, name -> name.length() > 1, Objects::nonNull);
}
}
@PropertySource(value = {"classpath:custom.json", "classpath:custom.json"}, factory = JsonPropertySourceFactory.class)
public class FooApplication {
}
- Using YAML Instead of Properties
- Spring @PropertySource using YAML
- Spring YAML Configuration
- Load spring-boot properties from json file
- @YamlPropertySource
- @JsonPropertySource
- Support yaml for @TestPropertySource
- SpringStreamBinding destination prefix/suffix by active profile