Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update OverrideConfiguration #202

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Issue [#196](https://github.com/42BV/beanmapper/issues/196) **Calls to the logger should not contain a call to String.formatted(Object...)**; Fixed by removing any formatting from performance logging. Trace-logging should keep the level of detail provided by the formatting.
- Issue [#197](https://github.com/42BV/beanmapper/issues/197) **Implement caching for Unproxy results.**; Created UnproxyResultStore, allowing for thread-safe caching and retrieval of unproxied classes.
- Issue [#199](https://github.com/42BV/beanmapper/issues/199) **Use of OverrideField causes excessive resource consumption.**; Use of OverrideField was phased out. OverrideField itself is now deprecated for removal.
- Issue [#201](https://github.com/42BV/beanmapper/issues/201) **Calls from OverrideConfiguration to parentConfiguration cause unnecessary overhead.**; Introduced fields in the OverrideConfiguration, to limit the overhead of calls to the parent configuration.

## [4.1.3] - 2024-03-27

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/io/beanmapper/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ public interface Configuration {
*/
List<BeanPair> getBeanPairs();

/**
* Retrieves the CollectionHandlerStore from the CoreConfiguration.
*
* @return The CollectionHandlerStore retrieved from the CoreConfiguration.
*/
CollectionHandlerStore getCollectionHandlerStore();

boolean isConverterChoosable();

void setConverterChoosable(boolean converterChoosable);
Expand Down Expand Up @@ -448,4 +455,11 @@ public interface Configuration {
* @param <V> The type of the associated value.
*/
<T, V> V getDefaultValueForClass(Class<T> targetClass);

/**
* Retrieved the Map containing the custom values for classes registered to the current mapping.
*
* @return Map containing custom values per type.
*/
Map<Class<?>, Object> getCustomDefaultValuesMap();
}
21 changes: 18 additions & 3 deletions src/main/java/io/beanmapper/config/CoreConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,8 @@ public void setFlushAfterClear(Trinary flushAfterClear) {
*/
@Override
public <T, V> V getDefaultValueForClass(Class<T> targetClass) {
return this.customDefaultValueMap.containsKey(targetClass)
? (V) this.customDefaultValueMap.get(targetClass)
: DefaultValues.defaultValueFor(targetClass);
Object defaultValue = customDefaultValueMap.get(targetClass);
return defaultValue != null ? (V) defaultValue : DefaultValues.defaultValueFor(targetClass);
}

/**
Expand All @@ -442,4 +441,20 @@ public <T, V> V getDefaultValueForClass(Class<T> targetClass) {
public <T, V> void addCustomDefaultValueForClass(Class<T> targetClass, V value) {
this.customDefaultValueMap.put(targetClass, value);
}

/**
* {@inheritDoc}
*/
@Override
public CollectionHandlerStore getCollectionHandlerStore() {
return this.collectionHandlerStore;
}

/**
* {@inheritDoc}
*/
@Override
public Map<Class<?>, Object> getCustomDefaultValuesMap() {
return customDefaultValueMap;
}
}
Loading
Loading