Skip to content

Commit

Permalink
Fix properties mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlauer committed Dec 18, 2018
1 parent 75f259b commit 6cfe7a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 3.1.4 (2018-12-18)

* [fix] Fix macro and function evaluation in properties mapping/unmapping.

# Version 3.1.3 (2018-12-03)

* [chg] Built and tested with OpenJDK 11 (minimum Java version still being 8).
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<groupId>org.seedstack.coffig</groupId>
<artifactId>coffig</artifactId>
<version>3.1.3-SNAPSHOT</version>
<version>3.1.4-SNAPSHOT</version>

<properties>
<shed.version>1.1.4</shed.version>
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/org/seedstack/coffig/mapper/PropertiesMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@

import java.lang.reflect.Type;
import java.util.Properties;
import org.seedstack.coffig.Coffig;
import org.seedstack.coffig.TreeNode;
import org.seedstack.coffig.node.MapNode;
import org.seedstack.coffig.node.ValueNode;
import org.seedstack.coffig.spi.ConfigurationMapper;

public class PropertiesMapper implements ConfigurationMapper {
private Coffig coffig;

@Override
public void initialize(Coffig coffig) {
this.coffig = coffig;
}

@Override
public boolean canHandle(Type type) {
return type instanceof Class && type.equals(Properties.class);
Expand All @@ -26,7 +33,8 @@ public Object map(TreeNode treeNode, Type type) {
Properties properties = new Properties();
if (treeNode.type() == TreeNode.Type.MAP_NODE) {
treeNode.namedNodes()
.forEach(namedNode -> properties.setProperty(namedNode.name(), namedNode.node().value()));
.forEach(namedNode -> properties.setProperty(namedNode.name(),
(String) coffig.getMapper().map(namedNode.node(), String.class)));
} else {
treeNode.nodes().forEach(item -> properties.setProperty(item.value(), ""));
}
Expand All @@ -38,7 +46,7 @@ public TreeNode unmap(Object object, Type type) {
MapNode mapNode = new MapNode();
((Properties) object).forEach((key, value) -> {
if (key != null) {
mapNode.set(String.valueOf(key), new ValueNode(String.valueOf(value)));
mapNode.set(String.valueOf(key), coffig.getMapper().unmap(value, String.class));
}
});
return mapNode;
Expand Down

0 comments on commit 6cfe7a5

Please sign in to comment.