Skip to content

Commit

Permalink
Added suppressing adapters to leave default values out of XML
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaehren committed Oct 22, 2024
1 parent 1ad0fbc commit 58266a3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* ModifiableVariable - A Variable Concept for Runtime Modifications
*
* Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
*
* Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0
*/
package de.rub.nds.modifiablevariable.util;

import jakarta.xml.bind.annotation.adapters.XmlAdapter;
import java.util.Objects;

public abstract class SuppressingBooleanAdapter extends XmlAdapter<String, Boolean> {

public abstract Boolean getValueToSuppress();

@Override
public Boolean unmarshal(String v) throws Exception {
if (v == null) {
return getValueToSuppress();
} else {
return Boolean.parseBoolean(v);
}
}

@Override
public String marshal(Boolean v) throws Exception {
if (Objects.equals(v, getValueToSuppress()) || v == null) {
return null;
}
return v.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* ModifiableVariable - A Variable Concept for Runtime Modifications
*
* Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
*
* Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0
*/
package de.rub.nds.modifiablevariable.util;

public class SuppressingFalseBooleanAdapter extends SuppressingBooleanAdapter {

@Override
public Boolean getValueToSuppress() {
return Boolean.FALSE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* ModifiableVariable - A Variable Concept for Runtime Modifications
*
* Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
*
* Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0
*/
package de.rub.nds.modifiablevariable.util;

public class SuppressingTrueBooleanAdapter extends SuppressingBooleanAdapter {
@Override
public Boolean getValueToSuppress() {
return Boolean.TRUE;
}
}

0 comments on commit 58266a3

Please sign in to comment.