Deep merge maps and JSON with configurable conflict resolution
implementation com.philiprehberger:deep-mergeDeep merge maps with configurable conflict resolution.
implementation("com.philiprehberger:deep-merge:0.2.0")
<dependency>
<groupId>com.philiprehberger</groupId>
<artifactId>deep-merge</artifactId>
<version>0.2.0</version>
</dependency>
import com.philiprehberger.deepmerge.*
val defaults = mapOf("db" to mapOf("host" to "localhost", "port" to 5432))
val overrides = mapOf("db" to mapOf("host" to "db.prod.example.com"))
val config = deepMerge(defaults, overrides)
// {"db": {"host": "db.prod.example.com", "port": 5432}}
// With configuration
deepMerge(a, b) {
onConflict = MergeStrategy.FIRST_WINS
onListConflict = ListMerge.APPEND
onNull = NullHandling.SKIP
}
// Diff two maps — returns only changed/added keys
val original = mapOf("db" to mapOf("host" to "localhost", "port" to 5432))
val modified = mapOf("db" to mapOf("host" to "db.prod.example.com", "port" to 5432))
val changes = diff(original, modified)
// {"db": {"host": "db.prod.example.com"}}
| Function / Class | Description |
|---|---|
deepMerge(vararg maps, config) | Deep merge maps with configurable strategies |
diff(original, modified) | Returns only keys/values that differ between two maps (deep comparison) |
MergeStrategy | Conflict resolution: LAST_WINS, FIRST_WINS, THROW |
ListMerge | List merging: REPLACE, APPEND, UNION |
NullHandling | Null values: KEEP or SKIP |
MergeConflictException | Thrown when THROW strategy encounters a conflict |
./gradlew test # Run tests
./gradlew build # Build JAR
If you find this project useful: